﻿// Decompiled with JetBrains decompiler
// Type: DnProcessSimulateCommands.RCSDecoupling.CUiRCSDecouplingDlg
// Assembly: DnProcessSimulateCommands, Version=2402.0.0.890, Culture=neutral, PublicKeyToken=null
// MVID: A885D881-AEDF-447E-852A-6F13102E089C
// Assembly location: C:\Program Files\Tecnomatix_2402\eMPower\DotNetCommands\DnProcessSimulateCommands.dll

using C1.Win.C1FlexGrid;
using EngineeringInternalExtension;
using EngineeringInternalExtension.DataTypes;
using System;
using System.Collections;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.ComponentModel;
using System.Diagnostics;
using System.Drawing;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Threading;
using System.Windows.Forms;
using System.Xml;
using Tecnomatix.Engineering;
using Tecnomatix.Engineering.Olp;
using Tecnomatix.Engineering.Olp.OLP_Utilities;
using Tecnomatix.Engineering.Olp.PrivateImplementationDetails;
using Tecnomatix.Engineering.PrivateImplementationDetails;
using Tecnomatix.Engineering.Ui;
using Tecnomatix.Engineering.Ui48;
using UiInternalControls;


namespace DnProcessSimulateCommands.RCSDecoupling;

public class CUiRCSDecouplingDlg : TxForm
{
  private List<CUiRCSDecoupleReadOnlyCell> m_readOnlyCells;
  private ArrayList m_robots;
  private TxRobot m_currentRobot;
  private ArrayList m_nonSimDisabledIndexes;
  private ArrayList m_simDisabledIndexes;
  private ArrayList m_VRCControlles;
  private Form m_robotSetupForm;
  private bool m_originalSelectionIsValid;
  private ToolTip m_tooltip;
  private CUiRCSDecouplingManipulatorFilterDlg m_filterDlg;
  private const int NUM_HEADER_ROWS = 2;
  private static string strControllersData = "Data/ControllersData";
  private static string strController = "Controller";
  private static string strAttrName = "Name";
  private static string strAttrSimulationAction = "RCSDecoupleSimulationAction";
  private static string strAttrNonSimulationAction = "RCSDecoupleNonSimulationAction";
  private static string MOP_STR = "MOP";
  private static string RCS_NON_SIMULATION_STR = "RRS Static";
  private static string RCS_STR = "RRS";
  private static string VRC_STR = "VRC";
  private static string VRC_NOT_SET_STATUS = "-------";
  private const int ROBOT_NAME_COL = 0;
  private const int CONTROLLER_NAME_COL = 1;
  private const int CONTROLLER_VERSION_COL = 2;
  private const int RCS_VERSION_COL = 3;
  private const int MOTION_PLANNER_COL = 4;
  private const int MANIPULATOR_TYPE_COL = 5;
  private const int FILTER_COL = 6;
  private const int RCS_STATUS_COL = 7;
  private const int VRC_HOST_COL = 8;
  private const int VRC_PORT_COL = 9;
  private const int VRC_NAME_COL = 10;
  private const int VRC_PROGRAM_POINTER_COL = 11;
  private string CONTROLLER_VERSION_PARAM = "OLP_CONTROLLER_VERSION";
  private string VRC_PORT_PARAM = "VRC_PORT_NUMBER";
  private string VRC_HOST_PARAM = "VRC_HOST_NAME";
  private string VRC_NAME_PARAM = "OLP_VRC_NAME";
  private string VRC_PROGRAM_POINTER_PARAM = "VRC_PROGRAM_POINTER_NAME";
  private int PORT_MINIMUM_VALUE = 1;
  private int PORT_MAXIMUM_VALUE = (int) ushort.MaxValue;
  private string DEFAULT_VRC_HOST = "localhost";
  private int DEFAULT_VRC_PORT = 8253;
  private IAsyncResult m_iftArResult;
  private static bool m_isSevrCallRunning = false;
  private SynchronizationContext m_syncContextCancel;
  private string m_logFilePath = "";
  private bool m_formLoaded;
  private IContainer components;
  private TxFlexGrid m_controllersGrid;
  private Button m_btnClose;
  private TxToolBarButton m_robotSetupButton;
  private TxToolBarButton m_validateButton;
  private ImageList m_imageList;
  private TxToolBarButton m_terminateRCSButton;
  private ContextMenuStrip contextMenuStrip1;
  private ToolStripMenuItem RRSToolStripMenuItem;
  private TxToolBarButton m_validateAllButton;
  private TxToolBarButton m_terminateAllRCSButton;
  private TxProgressBar m_validateProgressBar;
  private ToolStripMenuItem setAllWithVRCToolStripMenuItem;
  private ToolStripMenuItem setAllWithMOPToolStripMenuItem;
  private ToolStripMenuItem setAllWithRRSStaticToolStripMenuItem;
  private ToolTip m_InfoToolTip;
  private TxToolBar m_toolbar;
  private TxInfoButton m_InfoIcon;

  public CUiRCSDecouplingDlg()
  {
    this.m_readOnlyCells = new List<CUiRCSDecoupleReadOnlyCell>();
    this.m_robots = new ArrayList();
    this.m_nonSimDisabledIndexes = new ArrayList();
    this.m_simDisabledIndexes = new ArrayList();
    this.m_VRCControlles = new ArrayList();
    this.InitializeComponent();
    this.m_InfoIcon.TooltipText = CUiRCSDStringTable.TOOLTIP_INFO;
    ((ToolBarButton) this.m_robotSetupButton).Enabled = true;
    this.m_tooltip = new ToolTip();
    this.m_validateButton.SetImage(TxImageManager.GetImageByKey("InitializeRcsModule"));
    this.m_validateAllButton.SetImage(TxImageManager.GetImageByKey("InitializeAllRcsModules"));
    this.m_terminateRCSButton.SetImage(TxImageManager.GetImageByKey("TerminateRcsModule"));
    this.m_terminateAllRCSButton.SetImage(TxImageManager.GetImageByKey("TerminateAllRcsModule"));
    this.m_robotSetupButton.SetImage(TxImageManager.GetImageByKey("RobotSetup"));
    ((ToolBarButton) this.m_validateButton).ImageIndex = 0;
    ((ToolBarButton) this.m_validateAllButton).ImageIndex = 1;
    ((ToolBarButton) this.m_terminateRCSButton).ImageIndex = 2;
    ((ToolBarButton) this.m_terminateAllRCSButton).ImageIndex = 3;
    ((ToolBarButton) this.m_robotSetupButton).ImageIndex = 4;
    this.m_toolbar.InitImages();
  }

  protected SynchronizationContext SyncContextCancel => this.m_syncContextCancel;

  private void m_btnClose_Click(object sender, EventArgs e)
  {
    if (this.m_iftArResult != null && !this.m_iftArResult.IsCompleted)
    {
      Cursor current = Cursor.Current;
      Cursor.Current = Cursors.WaitCursor;
      CUiRCSDecouplingDlg.m_isSevrCallRunning = false;
      do
        ;
      while (!this.m_iftArResult.IsCompleted);
      Cursor.Current = current;
      this.RestoreEnablersState();
      this.m_iftArResult = (IAsyncResult) null;
    }
    else
    {
      this.UpdateRobots();
      ((Form) this).Close();
    }
  }

  private bool DoesRCSExistAndValid(TxRobot robot, ref bool isRCSTerminated)
  {
    return new TxRoboticControllerUtilities().DoesRCSExistAndValid(robot, ref isRCSTerminated);
  }

  private bool IsMultiRobotSystemSupported(string controllerName)
  {
    return new TxRoboticControllerUtilities().IsMultiRobotSystemSupported(controllerName);
  }

  private bool IsMultiRobotSystemRobot(ITxRobot robot)
  {
    bool flag1 = false;
    bool flag2 = robot is ITxComponent && (robot as ITxComponent).IsEquipment;
    ITxTypeFilter itxTypeFilter = (ITxTypeFilter) new TxTypeFilter(typeof (ITxRobot));
    if (robot is ITxObjectCollection objectCollection)
    {
      TxObjectList allDescendants = objectCollection.GetAllDescendants(itxTypeFilter);
      flag1 = ((allDescendants == null ? 0 : (((Collection<ITxObject>) allDescendants).Count > 1 ? 1 : 0)) & (flag2 ? 1 : 0)) != 0;
    }
    return flag1;
  }

  private void CUiRCSDecouplingDlg_Load(object sender, EventArgs e)
  {
    Cursor current = Cursor.Current;
    Cursor.Current = Cursors.WaitCursor;
    TxObjectList items = TxApplication.ActiveSelection.GetItems();
    if (((Collection<ITxObject>) items).Count == 1 && ((Collection<ITxObject>) items)[0] is TxRobot)
      this.m_originalSelectionIsValid = true;
    this.InitializeGrid();
    this.FindVRCControllers();
    this.FillRobots();
    this.RegisterToSelectionEvents();
    if (this.m_originalSelectionIsValid)
    {
      this.m_originalSelectionIsValid = false;
      TxApplication.ActiveSelection.SetItems(items);
    }
    this.UpdateValidateEnablers();
    this.UpdateTerminateAllRCSStatus();
    Cursor.Current = current;
    this.m_syncContextCancel = SynchronizationContext.Current;
    TxApplication.ActiveDocument.Unloading += new TxDocument_UnloadingEventHandler(this.ActiveDocument_Unloading);
    ((C1FlexGridBase) this.m_controllersGrid).Select(-1, -1);
    this.m_formLoaded = true;
  }

  private void ActiveDocument_Unloading(object sender, TxDocument_UnloadingEventArgs args)
  {
    ((Form) this).Close();
  }

  private void RegisterToSelectionEvents()
  {
    TxApplication.ActiveSelection.ItemsAdded += new TxSelection_ItemsAddedEventHandler(this.ActiveSelection_ItemsAdded);
    TxApplication.ActiveSelection.ItemsRemoved += new TxSelection_ItemsRemovedEventHandler(this.ActiveSelection_ItemsRemoved);
    TxApplication.ActiveSelection.ItemsSet += new TxSelection_ItemsSetEventHandler(this.ActiveSelection_ItemsSet);
  }

  private void UnregisterToSelectionEvents()
  {
    TxApplication.ActiveSelection.ItemsAdded -= new TxSelection_ItemsAddedEventHandler(this.ActiveSelection_ItemsAdded);
    TxApplication.ActiveSelection.ItemsRemoved -= new TxSelection_ItemsRemovedEventHandler(this.ActiveSelection_ItemsRemoved);
    TxApplication.ActiveSelection.ItemsSet -= new TxSelection_ItemsSetEventHandler(this.ActiveSelection_ItemsSet);
  }

  private void CUiRCSDecouplingDlg_FormClosed(object sender, FormClosedEventArgs e)
  {
    if (this.m_robotSetupForm != null)
    {
      this.m_robotSetupForm.Close();
      this.m_robotSetupForm = (Form) null;
    }
    this.UpdateRobots();
    this.UnregisterToSelectionEvents();
    TxApplication.ActiveDocument.Unloading -= new TxDocument_UnloadingEventHandler(this.ActiveDocument_Unloading);
  }

  private void ActiveSelection_ItemsRemoved(object sender, TxSelection_ItemsRemovedEventArgs args)
  {
    this.UpdateSelection();
  }

  private void ActiveSelection_ItemsAdded(object sender, TxSelection_ItemsAddedEventArgs args)
  {
    this.UpdateSelection();
  }

  private void ActiveSelection_ItemsSet(object sender, TxSelection_ItemsSetEventArgs args)
  {
    this.UpdateSelection();
  }

  private void UpdateSelection()
  {
    if (((Collection<ITxObject>) TxApplication.ActiveSelection.GetItems()).Count != 1)
      return;
    ITxObject itxObject = ((Collection<ITxObject>) TxApplication.ActiveSelection.GetItems())[0];
    if (!(itxObject is ITxRobot))
      return;
    ((C1FlexGridBase) this.m_controllersGrid).Select(this.m_robots.IndexOf((object) (itxObject as ITxRobot)) + 2, 0);
  }

  private void m_controllersGrid_BeforeEdit(object sender, RowColEventArgs e)
  {
    if (e.Col == 0)
      e.Cancel = true;
    if (e.Col == 2)
    {
      CellStyle cellStyle = ((C1FlexGridBase) this.m_controllersGrid).GetCellStyle(e.Row, 2);
      if (cellStyle == null || !(cellStyle.Name == "ReadOnly"))
        return;
      e.Cancel = true;
    }
    else if (e.Col == 5)
    {
      CellStyle cellStyle = ((C1FlexGridBase) this.m_controllersGrid).GetCellStyle(e.Row, 5);
      if (cellStyle == null || !(cellStyle.Name == "ReadOnly"))
        return;
      e.Cancel = true;
    }
    else if (e.Col == 3)
    {
      CellStyle cellStyle = ((C1FlexGridBase) this.m_controllersGrid).GetCellStyle(e.Row, 3);
      if (cellStyle == null || !(cellStyle.Name == "ReadOnly"))
        return;
      e.Cancel = true;
    }
    else if (e.Col == 4)
    {
      CellStyle cellStyle = ((C1FlexGridBase) this.m_controllersGrid).GetCellStyle(e.Row, 4);
      if (cellStyle == null || !(cellStyle.Name == "ReadOnly"))
        return;
      e.Cancel = true;
    }
    else if (e.Col == 7)
      e.Cancel = true;
    else if (e.Col == 8)
    {
      CellStyle cellStyle = ((C1FlexGridBase) this.m_controllersGrid).GetCellStyle(e.Row, 8);
      if (cellStyle == null || !(cellStyle.Name == "ReadOnly"))
        return;
      e.Cancel = true;
    }
    else if (e.Col == 9)
    {
      CellStyle cellStyle = ((C1FlexGridBase) this.m_controllersGrid).GetCellStyle(e.Row, 9);
      if (cellStyle == null || !(cellStyle.Name == "ReadOnly"))
        return;
      e.Cancel = true;
    }
    else if (e.Col == 10)
    {
      CellStyle cellStyle = ((C1FlexGridBase) this.m_controllersGrid).GetCellStyle(e.Row, 10);
      if (cellStyle == null || !(cellStyle.Name == "ReadOnly"))
        return;
      e.Cancel = true;
    }
    else
    {
      if (e.Col != 11)
        return;
      CellStyle cellStyle = ((C1FlexGridBase) this.m_controllersGrid).GetCellStyle(e.Row, 11);
      if (cellStyle == null || !(cellStyle.Name == "ReadOnly"))
        return;
      e.Cancel = true;
    }
  }

  private void ApplyMotionPlannerValue(int rawIndex)
  {
    bool isRCSTerminated = false;
    TxRobot robot = this.m_robots[rawIndex - 2] as TxRobot;
    object data = ((C1FlexGridBase) this.m_controllersGrid).GetData(rawIndex, 4);
    robot.IsRCSTurnedOffForSimulationActions = !data.Equals((object) CUiRCSDecouplingDlg.RCS_STR);
    robot.IsRCSTurnedOffForNonSimulationActions = !data.Equals((object) CUiRCSDecouplingDlg.RCS_STR) && !data.Equals((object) CUiRCSDecouplingDlg.RCS_NON_SIMULATION_STR);
    if (robot.IsRCSTurnedOffForSimulationActions && robot.IsRCSTurnedOffForNonSimulationActions && this.DoesRCSExistAndValid(robot, ref isRCSTerminated))
    {
      new TxRRSServicesProvider(robot).Terminate();
      ((C1FlexGridBase) this.m_controllersGrid).SetData(rawIndex, 7, (object) CUiRCSDecouplingDlg.VRC_NOT_SET_STATUS);
      this.UpdateTerminateAllRCSStatus();
    }
    if (data.Equals((object) CUiRCSDecouplingDlg.MOP_STR) || data.Equals((object) CUiRCSDecouplingDlg.VRC_STR))
    {
      if (data.Equals((object) CUiRCSDecouplingDlg.VRC_STR))
      {
        robot.IsVRC = true;
        TxRoboticStringParam instanceParameter1 = (TxRoboticStringParam) robot.GetInstanceParameter(this.VRC_HOST_PARAM);
        if (instanceParameter1 != null)
          ((C1FlexGridBase) this.m_controllersGrid).SetData(rawIndex, 8, (object) instanceParameter1.Value);
        else
          ((C1FlexGridBase) this.m_controllersGrid).SetData(rawIndex, 8, (object) this.DEFAULT_VRC_HOST);
        TxRoboticIntParam instanceParameter2 = (TxRoboticIntParam) robot.GetInstanceParameter(this.VRC_PORT_PARAM);
        if (instanceParameter2 != null)
          ((C1FlexGridBase) this.m_controllersGrid).SetData(rawIndex, 9, (object) instanceParameter2.Value);
        else
          ((C1FlexGridBase) this.m_controllersGrid).SetData(rawIndex, 9, (object) this.DEFAULT_VRC_PORT);
        TxRoboticStringParam instanceParameter3 = (TxRoboticStringParam) robot.GetInstanceParameter(this.VRC_NAME_PARAM);
        if (instanceParameter3 != null)
          ((C1FlexGridBase) this.m_controllersGrid).SetData(rawIndex, 10, (object) instanceParameter3.Value);
        else
          ((C1FlexGridBase) this.m_controllersGrid).SetData(rawIndex, 10, (object) ((TxBaseGeometryCreationObject) robot).Name);
        ((C1FlexGridBase) this.m_controllersGrid).SetCellStyle(rawIndex, 8, "");
        ((C1FlexGridBase) this.m_controllersGrid).SetCellStyle(rawIndex, 9, "");
        ((C1FlexGridBase) this.m_controllersGrid).SetCellStyle(rawIndex, 10, "");
        ((C1FlexGridBase) this.m_controllersGrid).SetCellStyle(rawIndex, 11, ((C1FlexGridBase) this.m_controllersGrid).Styles["ReadOnly"]);
        this.UpdateVRCProgramPointerColumn(rawIndex);
        this.DisableRRSColumns(rawIndex);
      }
      else if (robot.IsVRC)
      {
        robot.IsVRC = false;
        this.DisableVRCColumns(rawIndex);
        this.DisableRRSColumns(rawIndex);
      }
      if (data.Equals((object) CUiRCSDecouplingDlg.MOP_STR))
        this.DisableRRSColumns(rawIndex);
    }
    else
    {
      if (robot.IsVRC)
        robot.IsVRC = false;
      this.UpdateRCSVersionCombo(rawIndex);
      this.UpdateManipulatorTypeCombo(rawIndex);
      this.UpdateControllerVersionCombo(rawIndex);
      ((C1FlexGridBase) this.m_controllersGrid).SetCellStyle(rawIndex, 7, "");
      this.DisableVRCColumns(rawIndex);
    }
    this.UpdateValidateEnablers();
  }

  private void UpdateVRCProgramPointerColumn(int row)
  {
    TxRobot robot = this.m_robots[row - 2] as TxRobot;
    if (!TxRobot.op_Inequality(robot, (ITxObject) null) || robot == null)
      return;
    TxRobotController controller = robot.Controller;
    if (controller == null)
      return;
    TxOlpControllerUtilities controllerUtilities = new TxOlpControllerUtilities();
    ITxRoboticControllerVRCServices controllerVrcServices = (ITxRoboticControllerVRCServices) controllerUtilities.GetInterfaceImplementationFromController(controller.Name, typeof (ITxRoboticControllerVRCServices), typeof (TxControllerAttribute), "ControllerName") ?? (ITxRoboticControllerVRCServices) controllerUtilities.GetInterfaceImplementationFromController("default", typeof (ITxRoboticControllerVRCServices), typeof (TxControllerAttribute), "ControllerName");
    if (controllerVrcServices == null)
      return;
    ((ITxRoboticControllerServices) controllerVrcServices).Init(robot);
    if (!controllerVrcServices.IsProgramPointerSupported())
      return;
    TxRoboticStringParam instanceParameter = (TxRoboticStringParam) robot.GetInstanceParameter(this.VRC_PROGRAM_POINTER_PARAM);
    if (instanceParameter != null)
      ((C1FlexGridBase) this.m_controllersGrid).SetData(row, 11, (object) instanceParameter.Value);
    ((C1FlexGridBase) this.m_controllersGrid).SetCellStyle(row, 11, "");
  }

  private void DisableVRCColumns(int row)
  {
    ((C1FlexGridBase) this.m_controllersGrid).SetData(row, 8, (object) null);
    ((C1FlexGridBase) this.m_controllersGrid).SetData(row, 9, (object) null);
    ((C1FlexGridBase) this.m_controllersGrid).SetData(row, 10, (object) null);
    ((C1FlexGridBase) this.m_controllersGrid).SetData(row, 11, (object) null);
    ((C1FlexGridBase) this.m_controllersGrid).SetCellStyle(row, 8, ((C1FlexGridBase) this.m_controllersGrid).Styles["ReadOnly"]);
    ((C1FlexGridBase) this.m_controllersGrid).SetCellStyle(row, 9, ((C1FlexGridBase) this.m_controllersGrid).Styles["ReadOnly"]);
    ((C1FlexGridBase) this.m_controllersGrid).SetCellStyle(row, 10, ((C1FlexGridBase) this.m_controllersGrid).Styles["ReadOnly"]);
    ((C1FlexGridBase) this.m_controllersGrid).SetCellStyle(row, 11, ((C1FlexGridBase) this.m_controllersGrid).Styles["ReadOnly"]);
  }

  private void OnAfterEdit(int row, int col)
  {
    bool isRCSTerminated = false;
    TxRobot robot = this.m_robots[row - 2] as TxRobot;
    switch (col)
    {
      case 1:
        string str1 = ((C1FlexGridBase) this.m_controllersGrid).GetData(row, col).ToString();
        if (str1 == robot.Controller.Name)
          break;
        if (this.DoesRCSExistAndValid(robot, ref isRCSTerminated))
        {
          new TxRRSServicesProvider(robot).Terminate();
          ((C1FlexGridBase) this.m_controllersGrid).SetData(((C1FlexGridBase) this.m_controllersGrid).RowSel, 7, (object) CUiRCSDecouplingDlg.VRC_NOT_SET_STATUS);
        }
        if (str1 != robot.Controller.Name)
        {
          TxRobotController robotController = TxRobotControllerEx.CreateRobotController(robot, str1);
          TxRobotRRSController robotRrsController = robotController as TxRobotRRSController;
          robot.Controller = robotController;
        }
        if (str1 == "default")
        {
          this.DisableRRSColumns(row);
          ((C1FlexGridBase) this.m_controllersGrid).SetCellStyle(row, 2, ((C1FlexGridBase) this.m_controllersGrid).Styles["ReadOnly"]);
          ((C1FlexGridBase) this.m_controllersGrid).SetData(row, 2, (object) null);
          ((C1FlexGridBase) this.m_controllersGrid).SetCellStyle(row, 3, ((C1FlexGridBase) this.m_controllersGrid).Styles["ReadOnly"]);
          ((C1FlexGridBase) this.m_controllersGrid).SetCellStyle(row, 4, ((C1FlexGridBase) this.m_controllersGrid).Styles["ReadOnly"]);
          ((C1FlexGridBase) this.m_controllersGrid).SetData(row, 4, (object) CUiRCSDecouplingDlg.MOP_STR);
          ((C1FlexGridBase) this.m_controllersGrid).SetUserData(((C1FlexGridBase) this.m_controllersGrid).RowSel, 6, (object) null);
          if (!this.m_simDisabledIndexes.Contains((object) row))
            this.m_simDisabledIndexes.Add((object) row);
          if (!this.m_nonSimDisabledIndexes.Contains((object) row))
            this.m_nonSimDisabledIndexes.Add((object) row);
          this.DisableVRCColumns(row);
        }
        else
          this.FillRobotControllerData(row);
        this.UpdateTerminateAllRCSStatus();
        break;
      case 2:
        object data1 = ((C1FlexGridBase) this.m_controllersGrid).GetData(row, 2);
        if (data1 == null)
          break;
        TxRoboticStringParam roboticStringParam1 = new TxRoboticStringParam(this.CONTROLLER_VERSION_PARAM, data1.ToString());
        robot.SetInstanceParameter((TxRoboticParam) roboticStringParam1);
        break;
      case 3:
        TxRobotRRSController controller1 = robot.Controller as TxRobotRRSController;
        string str2 = ((C1FlexGridBase) this.m_controllersGrid).GetData(row, col).ToString();
        if (str2 != null && str2.StartsWith(CUiRCSDStringTable.INVALID_STR))
          str2 = str2.Substring(CUiRCSDStringTable.INVALID_STR.Length + 1);
        if (!(str2 != controller1.Version))
          break;
        if (this.DoesRCSExistAndValid(robot, ref isRCSTerminated))
        {
          new TxRRSServicesProvider(robot).Terminate();
          ((C1FlexGridBase) this.m_controllersGrid).SetData(((C1FlexGridBase) this.m_controllersGrid).RowSel, 7, (object) CUiRCSDecouplingDlg.VRC_NOT_SET_STATUS);
        }
        controller1.Version = str2;
        this.UpdateManipulatorTypeCombo(row);
        break;
      case 4:
        this.ApplyMotionPlannerValue(row);
        break;
      case 5:
        TxRobotRRSController controller2 = robot.Controller as TxRobotRRSController;
        object data2 = ((C1FlexGridBase) this.m_controllersGrid).GetData(row, col);
        if (data2 != null && (data2 == null || !(data2.ToString() != controller2.ManipulatorType)))
          break;
        if (this.DoesRCSExistAndValid(robot, ref isRCSTerminated))
        {
          new TxRRSServicesProvider(robot).Terminate();
          ((C1FlexGridBase) this.m_controllersGrid).SetData(((C1FlexGridBase) this.m_controllersGrid).RowSel, 7, (object) "-------");
        }
        controller2.ManipulatorType = data2 == null ? "" : data2.ToString();
        this.UpdateControllerVersionCombo(row);
        break;
      case 8:
        object data3 = ((C1FlexGridBase) this.m_controllersGrid).GetData(row, 8);
        if (data3 != null)
        {
          TxRoboticStringParam roboticStringParam2 = new TxRoboticStringParam(this.VRC_HOST_PARAM, data3.ToString());
          robot.SetInstanceParameter((TxRoboticParam) roboticStringParam2);
        }
        this.UpdateValidateEnablers();
        break;
      case 9:
        object data4 = ((C1FlexGridBase) this.m_controllersGrid).GetData(row, 9);
        if (data4 != null)
        {
          int num = int.Parse(data4.ToString());
          if (num >= this.PORT_MINIMUM_VALUE && num <= this.PORT_MAXIMUM_VALUE)
          {
            TxRoboticIntParam txRoboticIntParam = new TxRoboticIntParam(this.VRC_PORT_PARAM, num);
            robot.SetInstanceParameter((TxRoboticParam) txRoboticIntParam);
          }
          else
          {
            TxRoboticIntParam instanceParameter = (TxRoboticIntParam) robot.GetInstanceParameter(this.VRC_PORT_PARAM);
            if (instanceParameter != null)
              ((C1FlexGridBase) this.m_controllersGrid).SetData(row, 9, (object) instanceParameter.Value);
          }
        }
        this.UpdateValidateEnablers();
        break;
      case 10:
        object data5 = ((C1FlexGridBase) this.m_controllersGrid).GetData(row, 10);
        if (data5 != null)
        {
          TxRoboticStringParam roboticStringParam3 = new TxRoboticStringParam(this.VRC_NAME_PARAM, data5.ToString());
          robot.SetInstanceParameter((TxRoboticParam) roboticStringParam3);
        }
        this.UpdateValidateEnablers();
        break;
      case 11:
        object data6 = ((C1FlexGridBase) this.m_controllersGrid).GetData(row, 11);
        if (data6 == null)
          break;
        TxRoboticStringParam roboticStringParam4 = new TxRoboticStringParam(this.VRC_PROGRAM_POINTER_PARAM, data6.ToString());
        robot.SetInstanceParameter((TxRoboticParam) roboticStringParam4);
        break;
    }
  }

  private void m_controllersGrid_AfterEdit(object sender, RowColEventArgs e)
  {
    this.OnAfterEdit(e.Row, e.Col);
  }

  private void m_controllersGrid_SelChange(object sender, EventArgs e)
  {
    if (!this.m_formLoaded)
      return;
    this.FindSelectedRobotAndUpdateEnablers();
  }

  private void FindSelectedRobotAndUpdateEnablers()
  {
    bool flag1 = false;
    bool flag2 = false;
    bool isRCSTerminated = false;
    if (((C1FlexGridBase) this.m_controllersGrid).ColSel == 0)
    {
      TxObjectList txObjectList = new TxObjectList();
      for (int index = 0; index < ((RowColCollection) ((C1FlexGridBase) this.m_controllersGrid).Rows.Selected).Count; ++index)
        ((Collection<ITxObject>) txObjectList).Add(this.m_robots[((RowCol) ((C1FlexGridBase) this.m_controllersGrid).Rows.Selected[index]).Index - 2] as ITxObject);
      if (((Collection<ITxObject>) txObjectList).Count == 0 && ((C1FlexGridBase) this.m_controllersGrid).RowSel >= 2 && ((C1FlexGridBase) this.m_controllersGrid).RowSel < ((RowColCollection) ((C1FlexGridBase) this.m_controllersGrid).Rows).Count)
        ((Collection<ITxObject>) txObjectList).Add(this.m_robots[((C1FlexGridBase) this.m_controllersGrid).RowSel - 2] as ITxObject);
      if (!this.m_originalSelectionIsValid)
        TxApplication.ActiveSelection.SetItems(txObjectList);
      if (((Collection<ITxObject>) txObjectList).Count == 1)
      {
        TxRobot robot = ((Collection<ITxObject>) txObjectList)[0] as TxRobot;
        ((ToolBarButton) this.m_robotSetupButton).Enabled = true;
        if (this.DoesRCSExistAndValid(robot, ref isRCSTerminated))
        {
          ((ToolBarButton) this.m_terminateRCSButton).Enabled = true;
          flag2 = true;
        }
        flag1 = true;
      }
    }
    if (!flag1)
      ((ToolBarButton) this.m_robotSetupButton).Enabled = false;
    if (!flag2)
      ((ToolBarButton) this.m_terminateRCSButton).Enabled = false;
    this.UpdateValidateEnablers();
  }

  private void UpdateValidateEnablers()
  {
    if (((C1FlexGridBase) this.m_controllersGrid).RowSel < 2 || ((C1FlexGridBase) this.m_controllersGrid).ColSel != 0)
    {
      ((ToolBarButton) this.m_validateButton).Enabled = false;
    }
    else
    {
      object data1 = ((C1FlexGridBase) this.m_controllersGrid).GetData(((C1FlexGridBase) this.m_controllersGrid).RowSel, 4);
      if (data1 != null && data1.Equals((object) CUiRCSDecouplingDlg.MOP_STR))
        ((ToolBarButton) this.m_validateButton).Enabled = false;
      else if (data1 != null && data1.Equals((object) CUiRCSDecouplingDlg.VRC_STR))
      {
        object data2 = ((C1FlexGridBase) this.m_controllersGrid).GetData(((C1FlexGridBase) this.m_controllersGrid).RowSel, 8);
        object data3 = ((C1FlexGridBase) this.m_controllersGrid).GetData(((C1FlexGridBase) this.m_controllersGrid).RowSel, 9);
        if ((data2 == null || data2 != null && data2.ToString() == "") | (data3 == null || data3 != null && data3.ToString() == ""))
          ((ToolBarButton) this.m_validateButton).Enabled = false;
        else
          ((ToolBarButton) this.m_validateButton).Enabled = true;
      }
      else
        ((ToolBarButton) this.m_validateButton).Enabled = true;
    }
    ((ToolBarButton) this.m_validateAllButton).Enabled = false;
    for (int index = 2; index < ((RowColCollection) ((C1FlexGridBase) this.m_controllersGrid).Rows).Count; ++index)
    {
      object data4 = ((C1FlexGridBase) this.m_controllersGrid).GetData(index, 4);
      if (data4 != null && !data4.Equals((object) CUiRCSDecouplingDlg.MOP_STR))
      {
        if (data4.Equals((object) CUiRCSDecouplingDlg.VRC_STR))
        {
          object data5 = ((C1FlexGridBase) this.m_controllersGrid).GetData(index, 8);
          object data6 = ((C1FlexGridBase) this.m_controllersGrid).GetData(index, 9);
          if ((data5 == null || data5 != null && data5.ToString() == "") | (data6 == null || data6 != null && data6.ToString() == ""))
            continue;
        }
        ((ToolBarButton) this.m_validateAllButton).Enabled = true;
        break;
      }
    }
  }

  private void m_toolbar_ButtonClick(object sender, ToolBarButtonClickEventArgs e)
  {
    switch (((ToolBar) this.m_toolbar).Buttons.IndexOf(e.Button))
    {
      case 0:
        this.OnValidateSelected();
        break;
      case 1:
        this.OnValidateAll();
        break;
      case 2:
        this.OnTerminateRCS();
        break;
      case 3:
        this.OnTerminateAllRCS();
        break;
      case 4:
        this.OnRobotSetup();
        break;
    }
  }

  private void OnValidateSelected()
  {
    ((ToolBarButton) this.m_terminateRCSButton).Enabled = false;
    if (((C1FlexGridBase) this.m_controllersGrid).RowSel < 2 || ((C1FlexGridBase) this.m_controllersGrid).ColSel != 0)
    {
      int num1 = (int) TxMessageBox.Show(CUiRCSDStringTable.ERROR_SELECT_ROBOT, CUiRCSDStringTable.VALIDATE_TITLE, MessageBoxButtons.OK, MessageBoxIcon.Asterisk);
    }
    else
    {
      object data = ((C1FlexGridBase) this.m_controllersGrid).GetData(((C1FlexGridBase) this.m_controllersGrid).RowSel, 4);
      if (data != null && data.Equals((object) CUiRCSDecouplingDlg.VRC_STR))
      {
        List<TxRCSParamResults> results = (List<TxRCSParamResults>) null;
        if (!this.ValidateVRCConnection(((C1FlexGridBase) this.m_controllersGrid).RowSel, ref results))
          return;
        if (results == null)
        {
          int num2 = (int) TxMessageBox.Show(CUiRCSDStringTable.VRC_CONNECTION, CUiRCSDStringTable.VALIDATE_TITLE, MessageBoxButtons.OK, MessageBoxIcon.Asterisk);
        }
        else
        {
          if (results.Count <= 0)
            return;
          int num3 = (int) TxMessageBox.Show(results[0].Message, CUiRCSDStringTable.VALIDATE_TITLE, MessageBoxButtons.OK, MessageBoxIcon.Asterisk);
        }
      }
      else
      {
        Cursor current = Cursor.Current;
        Cursor.Current = Cursors.WaitCursor;
        TxRCSParamResults silentResult = (TxRCSParamResults) null;
        string RCSmessage;
        CUiRCSDecouplingDlg.RCSModuleStatus rcsModuleStatus = this.ValidateRobot(((C1FlexGridBase) this.m_controllersGrid).RowSel, out RCSmessage, ref silentResult);
        Cursor.Current = current;
        if (rcsModuleStatus == CUiRCSDecouplingDlg.RCSModuleStatus.RCSValidAndInitialized)
        {
          ((ToolBarButton) this.m_terminateRCSButton).Enabled = true;
          ((ToolBarButton) this.m_terminateAllRCSButton).Enabled = true;
        }
        if (rcsModuleStatus == CUiRCSDecouplingDlg.RCSModuleStatus.RCSUnvalidParams)
          return;
        int num4 = (int) TxMessageBox.Show(RCSmessage, CUiRCSDStringTable.VALIDATE_TITLE, MessageBoxButtons.OK, MessageBoxIcon.Asterisk);
      }
    }
  }

  private bool ValidateVRCConnection(int selectedRow, ref List<TxRCSParamResults> results)
  {
    bool flag = false;
    TxRobot robot = this.m_robots[selectedRow - 2] as TxRobot;
    ((C1FlexGridBase) this.m_controllersGrid).GetData(selectedRow, 1).ToString();
    if (TxRobot.op_Inequality(robot, (ITxObject) null) && robot != null)
    {
      TxRobotController controller = robot.Controller;
      if (controller != null)
      {
        TxOlpControllerUtilities controllerUtilities = new TxOlpControllerUtilities();
        ITxRoboticControllerVRCServices controllerVrcServices = (ITxRoboticControllerVRCServices) controllerUtilities.GetInterfaceImplementationFromController(controller.Name, typeof (ITxRoboticControllerVRCServices), typeof (TxControllerAttribute), "ControllerName") ?? (ITxRoboticControllerVRCServices) controllerUtilities.GetInterfaceImplementationFromController("default", typeof (ITxRoboticControllerVRCServices), typeof (TxControllerAttribute), "ControllerName");
        if (controllerVrcServices != null)
        {
          results = controllerVrcServices.CheckConnection(robot);
          flag = true;
        }
      }
    }
    return flag;
  }

  private CUiRCSDecouplingDlg.RCSModuleStatus ValidateRobot(
    int gridIndex,
    out string RCSmessage,
    ref TxRCSParamResults silentResult,
    bool silent = false)
  {
    TxRobot robot = this.m_robots[gridIndex - 2] as TxRobot;
    ITxRoboticControllerServices implementationFromController = (ITxRoboticControllerServices) new TxOlpControllerUtilities().GetInterfaceImplementationFromController(((C1FlexGridBase) this.m_controllersGrid).GetData(gridIndex, 1).ToString(), typeof (ITxRoboticControllerServices), typeof (TxControllerAttribute), "ControllerName");
    if (implementationFromController == null)
    {
      RCSmessage = "";
      return CUiRCSDecouplingDlg.RCSModuleStatus.RCSUnvalidParams;
    }
    bool flag = false;
    string str1 = "";
    try
    {
      if (silent)
      {
        TxRCSParamResults txRcsParamResults = implementationFromController.ValidateRCSParametersSilently(robot);
        if (txRcsParamResults != null)
        {
          RCSmessage = txRcsParamResults.Message;
          silentResult = txRcsParamResults;
          return CUiRCSDecouplingDlg.RCSModuleStatus.RCSUnvalidParams;
        }
        flag = true;
      }
      else
        flag = implementationFromController.ValidateRCSParameters(robot);
    }
    catch (TxRRSCanNotInitializeRcsException ex)
    {
      str1 = $"{((TxRRSException) ex).StatusMessage} ({((TxRRSException) ex).StatusCode.ToString()})";
    }
    if (!flag)
    {
      RCSmessage = str1;
      return CUiRCSDecouplingDlg.RCSModuleStatus.RCSUnvalidParams;
    }
    bool isRCSTerminated = false;
    string str2;
    CUiRCSDecouplingDlg.RCSModuleStatus rcsModuleStatus;
    if (this.DoesRCSExistAndValid(robot, ref isRCSTerminated))
    {
      str2 = $"{((TxBaseGeometryCreationObject) robot).Name}:{CUiRCSDStringTable.RCS_VALIDATED_MESSAGE} " + CUiRCSDStringTable.RCS_INITILIZED_MESSAGE;
      ((C1FlexGridBase) this.m_controllersGrid).SetData(gridIndex, 7, (object) CUiRCSDStringTable.RCS_STATUS_LOADED);
      rcsModuleStatus = CUiRCSDecouplingDlg.RCSModuleStatus.RCSValidAndInitialized;
    }
    else if (!isRCSTerminated)
    {
      str2 = $"{((TxBaseGeometryCreationObject) robot).Name}:{CUiRCSDStringTable.RCS_VALIDATED_MESSAGE}";
      rcsModuleStatus = CUiRCSDecouplingDlg.RCSModuleStatus.RCSValid;
    }
    else
    {
      str2 = ((TxBaseGeometryCreationObject) robot).Name + ":\n" + CUiRCSDStringTable.RCS_COMMUNICTION_FAILED;
      rcsModuleStatus = CUiRCSDecouplingDlg.RCSModuleStatus.RCSCommunicationFailed;
    }
    RCSmessage = str2;
    return rcsModuleStatus;
  }

  private void OnValidateAll()
  {
    string collectedMessage = "";
    string logMessage = "";
    Cursor current = Cursor.Current;
    Cursor.Current = Cursors.WaitCursor;
    ((ProgressBar) this.m_validateProgressBar).Value = 0;
    try
    {
      this.SetAsyncCallEnablersState();
      Func<string> func = (Func<string>) (() =>
      {
        CUiRCSDecouplingDlg.m_isSevrCallRunning = true;
        this.m_logFilePath = Path.GetTempPath() + $"RCSValidateAllRobots_{DateTime.Now.ToString("yyyyMMdd_HHmmss")}.log";
        TxReportWriterEx txReportWriterEx = new TxReportWriterEx(this.m_logFilePath);
        int num1 = 1;
        int num2 = ((RowColCollection) ((C1FlexGridBase) this.m_controllersGrid).Rows).Count - 2;
        for (int index = 2; index < ((RowColCollection) ((C1FlexGridBase) this.m_controllersGrid).Rows).Count && CUiRCSDecouplingDlg.m_isSevrCallRunning; ++index)
        {
          TxRobot robot = this.m_robots[index - 2] as TxRobot;
          switch (((C1FlexGridBase) this.m_controllersGrid).GetData(index, 1).ToString())
          {
            case "default":
              collectedMessage += ((TxBaseGeometryCreationObject) robot).Name;
              collectedMessage = $"{collectedMessage}: {CUiRCSDStringTable.DEFAULT_CONTROLLER_SELECTED}";
              collectedMessage += "\n";
              ++num1;
              break;
            default:
              object data = ((C1FlexGridBase) this.m_controllersGrid).GetData(index, 4);
              if (data != null && !data.Equals((object) CUiRCSDecouplingDlg.MOP_STR) && !data.Equals((object) CUiRCSDecouplingDlg.VRC_STR))
              {
                TxRCSParamResults silentResult = (TxRCSParamResults) null;
                string RCSmessage;
                CUiRCSDecouplingDlg.RCSModuleStatus rcsModuleStatus = this.ValidateRobot(index, out RCSmessage, ref silentResult, true);
                if (silentResult != null)
                  logMessage = $"{((TxBaseGeometryCreationObject) robot).Name}:{silentResult.Severity.ToString()} - {silentResult.Message}";
                else
                  logMessage = RCSmessage;
                txReportWriterEx.WriteLine(logMessage);
                txReportWriterEx.WriteLine(string.Empty);
                if (rcsModuleStatus != CUiRCSDecouplingDlg.RCSModuleStatus.RCSUnvalidParams)
                {
                  collectedMessage += RCSmessage;
                  collectedMessage += "\n";
                }
                else
                {
                  collectedMessage += ((TxBaseGeometryCreationObject) robot).Name;
                  collectedMessage = $"{collectedMessage}: {CUiRCSDStringTable.RCS_FAILED_TO_INITIALIZE}";
                  collectedMessage += "\n";
                }
              }
              else if (data != null && data.Equals((object) CUiRCSDecouplingDlg.VRC_STR))
              {
                List<TxRCSParamResults> results = (List<TxRCSParamResults>) null;
                if (this.ValidateVRCConnection(index, ref results))
                  logMessage = results == null || results.Count <= 0 ? $"{((TxBaseGeometryCreationObject) robot).Name}:{CUiRCSDStringTable.VRC_CONNECTION}" : $"{((TxBaseGeometryCreationObject) robot).Name}:{results[0].Message}";
                txReportWriterEx.WriteLine(logMessage);
                txReportWriterEx.WriteLine(string.Empty);
                collectedMessage += logMessage;
                collectedMessage += "\n\n";
              }
              else
              {
                collectedMessage += ((TxBaseGeometryCreationObject) robot).Name;
                collectedMessage = $"{collectedMessage}: {CUiRCSDStringTable.NON_SIMULATION_WAS_NOT_SELECTED}";
                collectedMessage += "\n";
              }
              this.SyncContextCancel.Post(new SendOrPostCallback(this.SetProgressValue), (object) new object[1]
              {
                (object) (num1 * 100 / num2)
              });
              ++num1;
              break;
          }
        }
        txReportWriterEx.Close();
        return collectedMessage;
      });
      Action<IAsyncResult> action = (Action<IAsyncResult>) (ar =>
      {
        CUiRCSDecouplingDlg.m_isSevrCallRunning = false;
        Func<string> asyncState = (Func<string>) ar.AsyncState;
        this.SyncContextCancel.Send(new SendOrPostCallback(this.ValidateAllCompleted), (object) new object[1]
        {
          (object) collectedMessage
        });
      });
      this.m_iftArResult = func.BeginInvoke(new AsyncCallback(action.Invoke), (object) func);
      Cursor.Current = current;
    }
    catch (Exception ex)
    {
      this.m_iftArResult = (IAsyncResult) null;
      Cursor.Current = current;
      this.RestoreEnablersState();
    }
  }

  private void SetProgressValue(object state)
  {
    ((ProgressBar) this.m_validateProgressBar).Value = (int) ((object[]) state)[0];
  }

  private void ValidateAllCompleted(object state)
  {
    string str = (string) ((object[]) state)[0];
    if (str != null && str.Length > 0 && TxMessageBox.ShowModal(str + "\n" + CUiRCSDStringTable.SEE_LOG_FILE_MSG, CUiRCSDStringTable.VALIDATE_TITLE, MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes && new FileInfo(this.m_logFilePath).Exists)
      Process.Start(this.m_logFilePath);
    this.RestoreEnablersState();
  }

  private void RestoreEnablersState()
  {
    ((Control) this.m_validateProgressBar).Visible = false;
    ((ToolBarButton) this.m_validateButton).Enabled = true;
    ((ToolBarButton) this.m_validateAllButton).Enabled = true;
    ((ToolBarButton) this.m_robotSetupButton).Enabled = true;
    ((Control) this.m_controllersGrid).Enabled = true;
    this.FindSelectedRobotAndUpdateEnablers();
    this.UpdateTerminateAllRCSStatus();
    this.m_btnClose.Text = CUiRCSDStringTable.CLOSE_LABEL;
  }

  private void SetAsyncCallEnablersState()
  {
    ((Control) this.m_validateProgressBar).Visible = true;
    this.m_btnClose.Text = CUiRCSDStringTable.CANCEL_LABEL;
    ((ToolBarButton) this.m_validateButton).Enabled = false;
    ((ToolBarButton) this.m_validateAllButton).Enabled = false;
    ((ToolBarButton) this.m_terminateAllRCSButton).Enabled = false;
    ((ToolBarButton) this.m_terminateRCSButton).Enabled = false;
    ((ToolBarButton) this.m_robotSetupButton).Enabled = false;
    ((Control) this.m_controllersGrid).Enabled = false;
  }

  private void OnRobotSetup()
  {
    TxRobot robot = this.m_robots[((C1FlexGridBase) this.m_controllersGrid).RowSel - 2] as TxRobot;
    ITxRobotSetup implementationFromController = (ITxRobotSetup) new TxOlpControllerUtilities().GetInterfaceImplementationFromController(((C1FlexGridBase) this.m_controllersGrid).GetData(((C1FlexGridBase) this.m_controllersGrid).RowSel, 1).ToString(), typeof (ITxRobotSetup), typeof (TxRobotSetupAttribute), "ControllerName");
    if (implementationFromController == null)
      return;
    TxRobotSetupManager.CloseAnyForm();
    this.m_robotSetupForm = implementationFromController.GetRobotSetupForm((ITxRobot) robot);
    if (this.m_robotSetupForm == null)
      return;
    Cursor current = Cursor.Current;
    Cursor.Current = Cursors.WaitCursor;
    this.m_robotSetupForm.Show();
    this.m_currentRobot = robot;
    this.m_robotSetupForm.FormClosed += new FormClosedEventHandler(this.m_robotSetupForm_FormClosed);
    Cursor.Current = current;
    TxRobotSetupManager.Add(this.m_robotSetupForm);
  }

  private void m_robotSetupForm_FormClosed(object sender, FormClosedEventArgs e)
  {
    bool isRCSTerminated = false;
    if (TxRobot.op_Inequality(this.m_currentRobot, (ITxObject) null))
    {
      int num = this.m_robots.IndexOf((object) this.m_currentRobot) + 2;
      if (this.DoesRCSExistAndValid(this.m_currentRobot, ref isRCSTerminated))
      {
        ((C1FlexGridBase) this.m_controllersGrid).SetData(num, 7, (object) CUiRCSDStringTable.RCS_STATUS_LOADED);
        ((ToolBarButton) this.m_terminateRCSButton).Enabled = true;
        ((ToolBarButton) this.m_terminateAllRCSButton).Enabled = true;
      }
      else
      {
        ((C1FlexGridBase) this.m_controllersGrid).SetData(num, 7, (object) CUiRCSDecouplingDlg.VRC_NOT_SET_STATUS);
        ((ToolBarButton) this.m_terminateRCSButton).Enabled = false;
      }
      if (this.m_currentRobot.GetInstanceParameter(this.CONTROLLER_VERSION_PARAM) is TxRoboticStringParam instanceParameter)
      {
        string str = instanceParameter.Value;
        ((C1FlexGridBase) this.m_controllersGrid).SetData(num, 2, (object) str);
      }
      this.m_currentRobot = (TxRobot) null;
    }
    this.m_robotSetupForm = (Form) null;
  }

  private void OnTerminateAllRCS()
  {
    Cursor current = Cursor.Current;
    Cursor.Current = Cursors.WaitCursor;
    bool isRCSTerminated = false;
    string str1 = "";
    for (int index = 2; index < ((RowColCollection) ((C1FlexGridBase) this.m_controllersGrid).Rows).Count; ++index)
    {
      TxRobot robot = this.m_robots[index - 2] as TxRobot;
      string str2 = str1 + ((TxBaseGeometryCreationObject) robot).Name + ":";
      if (this.DoesRCSExistAndValid(robot, ref isRCSTerminated))
      {
        new TxRRSServicesProvider(robot).Terminate();
        str1 = str2 + CUiRCSDStringTable.RCS_TERMINATED_MESSAGE + "\n";
      }
      else
        str1 = str2 + CUiRCSDStringTable.RCS_NOT_LOADED_MESSAGE + "\n";
      ((C1FlexGridBase) this.m_controllersGrid).SetData(index, 7, (object) CUiRCSDecouplingDlg.VRC_NOT_SET_STATUS);
    }
    int num = (int) TxMessageBox.ShowModal(str1, CUiRCSDStringTable.TERMINATE_TITLE, MessageBoxButtons.OK, MessageBoxIcon.Asterisk);
    ((ToolBarButton) this.m_terminateRCSButton).Enabled = false;
    ((ToolBarButton) this.m_terminateAllRCSButton).Enabled = false;
    Cursor.Current = current;
  }

  private void UpdateTerminateAllRCSStatus()
  {
    bool flag = false;
    foreach (TxRobot robot in this.m_robots)
    {
      bool isRCSTerminated = false;
      if (this.DoesRCSExistAndValid(robot, ref isRCSTerminated))
      {
        flag = true;
        break;
      }
    }
    ((ToolBarButton) this.m_terminateAllRCSButton).Enabled = flag;
  }

  private void OnTerminateRCS()
  {
    Cursor current = Cursor.Current;
    Cursor.Current = Cursors.WaitCursor;
    bool isRCSTerminated = false;
    TxRobot robot = this.m_robots[((C1FlexGridBase) this.m_controllersGrid).RowSel - 2] as TxRobot;
    if (this.DoesRCSExistAndValid(robot, ref isRCSTerminated))
      new TxRRSServicesProvider(robot).Terminate();
    int num = (int) TxMessageBox.Show(CUiRCSDStringTable.RCS_TERMINATED_MESSAGE, CUiRCSDStringTable.TERMINATE_TITLE, MessageBoxButtons.OK, MessageBoxIcon.Asterisk);
    ((C1FlexGridBase) this.m_controllersGrid).SetData(((C1FlexGridBase) this.m_controllersGrid).RowSel, 7, (object) CUiRCSDecouplingDlg.VRC_NOT_SET_STATUS);
    ((ToolBarButton) this.m_terminateRCSButton).Enabled = false;
    this.UpdateTerminateAllRCSStatus();
    Cursor.Current = current;
  }

  private void m_controllersGrid_MouseDown(object sender, MouseEventArgs e)
  {
    HitTestInfo hitTestInfo = ((C1FlexGridBase) this.m_controllersGrid).HitTest(e.X, e.Y);
    HashSet<string> columnValues = this.GetColumnValues(1);
    if (e.Button != MouseButtons.Right)
      return;
    bool flag = columnValues.Count == 1 && columnValues.Contains("default");
    if (((C1FlexGridBase) this.m_controllersGrid).MouseCol == 4)
    {
      if (flag || ((C1FlexGridBase) this.m_controllersGrid).MouseRow != 0 && ((C1FlexGridBase) this.m_controllersGrid).MouseRow != 1)
        return;
      this.contextMenuStrip1.Show((Control) this.m_controllersGrid, e.X, e.Y);
    }
    else
    {
      if (!this.ShouldShowSetAllContextMenu(hitTestInfo, columnValues))
        return;
      HashSet<string> columnPossibleValues = this.GetAllColumnPossibleValues(((HitTestInfo) ref hitTestInfo).Column);
      columnPossibleValues.Add(string.Empty);
      List<string> list = columnPossibleValues.ToList<string>();
      list.Sort();
      ToolStripMenuItem[] toolStripItems = new ToolStripMenuItem[list.Count];
      for (int index = 0; index < list.Count; ++index)
        toolStripItems[index] = new ToolStripMenuItem(list[index]);
      ContextMenuStrip contextMenuStrip = new ContextMenuStrip();
      contextMenuStrip.Tag = (object) ((HitTestInfo) ref hitTestInfo).Column;
      contextMenuStrip.Items.AddRange((ToolStripItem[]) toolStripItems);
      contextMenuStrip.ItemClicked += new ToolStripItemClickedEventHandler(this.ContextMenuStrip_ItemClicked);
      contextMenuStrip.Show((Control) this.m_controllersGrid, e.X, e.Y);
    }
  }

  private void ContextMenuStrip_ItemClicked(object sender, ToolStripItemClickedEventArgs e)
  {
    if (e.ClickedItem == null || !(e.ClickedItem.GetCurrentParent().Tag is int tag) || tag <= -1)
      return;
    ((C1FlexGridBase) this.m_controllersGrid).Select(0, 0);
    for (int row = 2; row < ((RowColCollection) ((C1FlexGridBase) this.m_controllersGrid).Rows).Count; ++row)
    {
      CellStyle cellStyle = ((C1FlexGridBase) this.m_controllersGrid).GetCellStyle(row, tag);
      if (cellStyle == null || cellStyle.Name != "ReadOnly")
      {
        ((C1FlexGridBase) this.m_controllersGrid).SetData(row, tag, (object) e.ClickedItem.Text);
        this.OnAfterEdit(row, tag);
      }
    }
  }

  private ArrayList GetSubDirectories(string directory)
  {
    ArrayList subDirectories = new ArrayList();
    subDirectories.Add((object) directory);
    for (int index = 0; index < subDirectories.Count; ++index)
    {
      string[] directories = Directory.GetDirectories((string) subDirectories[index]);
      if (directories.Length != 0)
        subDirectories.AddRange((ICollection) directories);
    }
    return subDirectories;
  }

  private XmlDocument GetXmlControllersDocument(ref string fname)
  {
    foreach (string file in Directory.GetFiles(new TxOLPUtilities().GetOLPInstallationDirectory(), "*.xml"))
    {
      try
      {
        XmlDocument controllersDocument = new XmlDocument();
        controllersDocument.Load(file);
        if (controllersDocument.SelectSingleNode(CUiRCSDecouplingDlg.strControllersData) != null)
        {
          fname = file;
          return controllersDocument;
        }
      }
      catch (Exception ex)
      {
      }
    }
    return (XmlDocument) null;
  }

  private void UpdateControllers()
  {
    TxRCSDecouple txRcsDecouple = new TxRCSDecouple();
    string empty = string.Empty;
    XmlDocument controllersDocument = this.GetXmlControllersDocument(ref empty);
    for (int index = 1; index < ((RowColCollection) ((C1FlexGridBase) this.m_controllersGrid).Rows).Count; ++index)
    {
      txRcsDecouple.UpdateController((string) ((C1FlexGridBase) this.m_controllersGrid).GetData(index, 0), (bool) ((C1FlexGridBase) this.m_controllersGrid).GetData(index, 2), (bool) ((C1FlexGridBase) this.m_controllersGrid).GetData(index, 1));
      if (controllersDocument != null)
        this.SaveControllerData(controllersDocument, (string) ((C1FlexGridBase) this.m_controllersGrid).GetData(index, 0), (bool) ((C1FlexGridBase) this.m_controllersGrid).GetData(index, 2), (bool) ((C1FlexGridBase) this.m_controllersGrid).GetData(index, 1));
    }
    controllersDocument?.Save(empty);
  }

  private void UpdateRobots()
  {
    int num = 2;
    bool isRCSTerminated = false;
    foreach (TxRobot robot in this.m_robots)
    {
      object data1 = ((C1FlexGridBase) this.m_controllersGrid).GetData(num, 2);
      if (data1 != null)
      {
        TxRoboticStringParam roboticStringParam = new TxRoboticStringParam(this.CONTROLLER_VERSION_PARAM, data1.ToString());
        robot.SetInstanceParameter((TxRoboticParam) roboticStringParam);
      }
      object data2 = ((C1FlexGridBase) this.m_controllersGrid).GetData(num, 4);
      if (data2 != null)
      {
        robot.IsRCSTurnedOffForSimulationActions = !data2.Equals((object) CUiRCSDecouplingDlg.RCS_STR);
        robot.IsRCSTurnedOffForNonSimulationActions = !data2.Equals((object) CUiRCSDecouplingDlg.RCS_STR) && !data2.Equals((object) CUiRCSDecouplingDlg.RCS_NON_SIMULATION_STR);
      }
      if (robot.Controller.Name != "default" && robot.IsRCSTurnedOffForNonSimulationActions && robot.IsRCSTurnedOffForSimulationActions && this.DoesRCSExistAndValid(robot, ref isRCSTerminated))
        new TxRRSServicesProvider(robot).Terminate();
      if (robot.IsVRC)
      {
        object data3 = ((C1FlexGridBase) this.m_controllersGrid).GetData(num, 8);
        if (data3 != null)
        {
          TxRoboticStringParam roboticStringParam = new TxRoboticStringParam(this.VRC_HOST_PARAM, data3.ToString());
          robot.SetInstanceParameter((TxRoboticParam) roboticStringParam);
        }
        object data4 = ((C1FlexGridBase) this.m_controllersGrid).GetData(num, 10);
        if (data4 != null)
        {
          TxRoboticStringParam roboticStringParam = new TxRoboticStringParam(this.VRC_NAME_PARAM, data4.ToString());
          robot.SetInstanceParameter((TxRoboticParam) roboticStringParam);
        }
        object data5 = ((C1FlexGridBase) this.m_controllersGrid).GetData(num, 9);
        if (data5 != null)
        {
          TxRoboticIntParam txRoboticIntParam = new TxRoboticIntParam(this.VRC_PORT_PARAM, int.Parse(data5.ToString()));
          robot.SetInstanceParameter((TxRoboticParam) txRoboticIntParam);
        }
        object data6 = ((C1FlexGridBase) this.m_controllersGrid).GetData(num, 11);
        if (data6 != null)
        {
          TxRoboticStringParam roboticStringParam = new TxRoboticStringParam(this.VRC_PROGRAM_POINTER_PARAM, data6.ToString());
          robot.SetInstanceParameter((TxRoboticParam) roboticStringParam);
        }
      }
      ++num;
    }
  }

  private void SaveControllerData(
    XmlDocument xmlDoc,
    string controllerName,
    bool simulationActions,
    bool nonSimulationActions)
  {
    XmlNode xmlNode = xmlDoc.SelectSingleNode(CUiRCSDecouplingDlg.strControllersData);
    if (xmlNode == null)
      return;
    foreach (XmlNode selectNode in xmlNode.SelectNodes(CUiRCSDecouplingDlg.strController))
    {
      if (selectNode.Attributes.Count > 0)
      {
        XmlAttribute namedItem1 = (XmlAttribute) selectNode.Attributes.GetNamedItem(CUiRCSDecouplingDlg.strAttrName);
        if (namedItem1 != null && namedItem1.Value == controllerName)
        {
          XmlAttribute namedItem2 = (XmlAttribute) selectNode.Attributes.GetNamedItem(CUiRCSDecouplingDlg.strAttrSimulationAction);
          if (namedItem2 != null)
          {
            namedItem2.Value = simulationActions.ToString();
            selectNode.Attributes.SetNamedItem((XmlNode) namedItem2);
          }
          else
          {
            XmlAttribute attribute = xmlDoc.CreateAttribute(CUiRCSDecouplingDlg.strAttrSimulationAction);
            attribute.Value = simulationActions.ToString();
            selectNode.Attributes.Append(attribute);
          }
          XmlAttribute namedItem3 = (XmlAttribute) selectNode.Attributes.GetNamedItem(CUiRCSDecouplingDlg.strAttrNonSimulationAction);
          if (namedItem3 != null)
          {
            namedItem3.Value = nonSimulationActions.ToString();
            selectNode.Attributes.SetNamedItem((XmlNode) namedItem3);
          }
          else
          {
            XmlAttribute attribute = xmlDoc.CreateAttribute(CUiRCSDecouplingDlg.strAttrNonSimulationAction);
            attribute.Value = nonSimulationActions.ToString();
            selectNode.Attributes.Append(attribute);
          }
        }
      }
    }
  }

  private void FillRobots()
  {
    TxObjectList allDescendants = TxApplication.ActiveDocument.PhysicalRoot.GetAllDescendants((ITxTypeFilter) new TxTypeFilter(typeof (TxRobot)));
    int pos = 2;
    foreach (ITxRobot robot in (Collection<ITxObject>) allDescendants)
    {
      this.m_robots.Add((object) robot);
      RowCollection rows = ((C1FlexGridBase) this.m_controllersGrid).Rows;
      ((RowColCollection) rows).Count = ((RowColCollection) rows).Count + 1;
      this.AddRobotToGrid(pos, robot);
      ++pos;
    }
  }

  private void InitializeGrid()
  {
    ((RowColCollection) ((C1FlexGridBase) this.m_controllersGrid).Rows).Count = 2;
    ((RowCol) ((C1FlexGridBase) this.m_controllersGrid).Rows[0]).AllowMerging = true;
    ((RowCol) ((C1FlexGridBase) this.m_controllersGrid).Rows[1]).AllowMerging = true;
    CellRange cellRange1 = ((C1FlexGridBase) this.m_controllersGrid).GetCellRange(0, 0, 1, 0);
    ((CellRange) ref cellRange1).Data = (object) CUiRCSDStringTable.ROBOT_NAME_HEADER;
    CellRange cellRange2 = ((C1FlexGridBase) this.m_controllersGrid).GetCellRange(1, 1, 1, 1);
    ((CellRange) ref cellRange2).Data = (object) CUiRCSDStringTable.CONTROLLER_NAME_HEADER;
    CellRange cellRange3 = ((C1FlexGridBase) this.m_controllersGrid).GetCellRange(1, 2, 1, 2);
    ((CellRange) ref cellRange3).Data = (object) CUiRCSDStringTable.CONTROLLER_VERSION_HEADER;
    CellRange cellRange4 = ((C1FlexGridBase) this.m_controllersGrid).GetCellRange(0, 1, 0, 3);
    ((CellRange) ref cellRange4).Data = (object) CUiRCSDStringTable.CONTROLLER_HEADER;
    CellRange cellRange5 = ((C1FlexGridBase) this.m_controllersGrid).GetCellRange(0, 4, 1, 4);
    ((CellRange) ref cellRange5).Data = (object) CUiRCSDStringTable.MOTION_PLANNER_HEADER;
    CellRange cellRange6 = ((C1FlexGridBase) this.m_controllersGrid).GetCellRange(0, 5, 0, 7);
    ((CellRange) ref cellRange6).Data = (object) CUiRCSDStringTable.RRS_HEADER;
    CellRange cellRange7 = ((C1FlexGridBase) this.m_controllersGrid).GetCellRange(1, 3, 1, 3);
    ((CellRange) ref cellRange7).Data = (object) CUiRCSDStringTable.RCS_VERSION_HEADER;
    CellRange cellRange8 = ((C1FlexGridBase) this.m_controllersGrid).GetCellRange(1, 5, 1, 5);
    ((CellRange) ref cellRange8).Data = (object) CUiRCSDStringTable.MANIPULATOR_TYPE_HEADER;
    CellRange cellRange9 = ((C1FlexGridBase) this.m_controllersGrid).GetCellRange(1, 6, 1, 6);
    ((CellRange) ref cellRange9).Data = (object) " ";
    CellRange cellRange10 = ((C1FlexGridBase) this.m_controllersGrid).GetCellRange(1, 7, 1, 7);
    ((CellRange) ref cellRange10).Data = (object) CUiRCSDStringTable.RCS_STATUS_HEADER;
    CellRange cellRange11 = ((C1FlexGridBase) this.m_controllersGrid).GetCellRange(1, 8, 1, 8);
    ((CellRange) ref cellRange11).Data = (object) CUiRCSDStringTable.VRC_HOST_HEADER;
    CellRange cellRange12 = ((C1FlexGridBase) this.m_controllersGrid).GetCellRange(1, 10, 1, 10);
    ((CellRange) ref cellRange12).Data = (object) CUiRCSDStringTable.VRC_NAME_HEADER;
    CellRange cellRange13 = ((C1FlexGridBase) this.m_controllersGrid).GetCellRange(1, 9, 1, 9);
    ((CellRange) ref cellRange13).Data = (object) CUiRCSDStringTable.VRC_PORT_HEADER;
    CellRange cellRange14 = ((C1FlexGridBase) this.m_controllersGrid).GetCellRange(0, 8, 0, 11);
    ((CellRange) ref cellRange14).Data = (object) CUiRCSDStringTable.VRC_HEADER;
    CellRange cellRange15 = ((C1FlexGridBase) this.m_controllersGrid).GetCellRange(1, 11, 1, 11);
    ((CellRange) ref cellRange15).Data = (object) CUiRCSDStringTable.VRC_PROGRAM_POINTER_HEADER;
    ((C1FlexGridBase) this.m_controllersGrid).Styles.Add("Regular").BackColor = ((C1FlexGridBase) this.m_controllersGrid).Styles["Normal"].BackColor;
    ((RowColCollection) ((C1FlexGridBase) this.m_controllersGrid).Cols).Frozen = 1;
    CUiRCSUpDown cuiRcsUpDown = new CUiRCSUpDown();
    cuiRcsUpDown.BorderStyle = BorderStyle.None;
    cuiRcsUpDown.Minimum = (Decimal) this.PORT_MINIMUM_VALUE;
    cuiRcsUpDown.Maximum = (Decimal) this.PORT_MAXIMUM_VALUE;
    ((RowCol) ((C1FlexGridBase) this.m_controllersGrid).Cols[9]).Editor = (Control) cuiRcsUpDown;
  }

  private void AddRobotToGrid(int pos, ITxRobot robot)
  {
    CellStyle cellStyle1 = ((C1FlexGridBase) this.m_controllersGrid).Styles.Add("RobotsFixed");
    cellStyle1.TextAlign = (TextAlignEnum) 1;
    ((C1FlexGridBase) this.m_controllersGrid).SetCellStyle(pos, 0, cellStyle1);
    ((C1FlexGridBase) this.m_controllersGrid).SetData(pos, 0, (object) ((ITxObject) robot).Name);
    ArrayList teachPendantsNames = new TxOLPUtilities().GetInstalledTeachPendantsNames();
    CellStyle cellStyle2 = ((C1FlexGridBase) this.m_controllersGrid).Styles.Add("ControllersCombo" + ((ITxObject) robot).Id);
    cellStyle2.ComboList = "";
    bool flag1 = this.IsMultiRobotSystemRobot(robot);
    foreach (string controllerName in teachPendantsNames)
    {
      bool flag2 = true;
      if (flag1 && !this.IsMultiRobotSystemSupported(controllerName))
        flag2 = false;
      if (flag2)
      {
        cellStyle2.ComboList += controllerName;
        cellStyle2.ComboList += "|";
      }
    }
    ((C1FlexGridBase) this.m_controllersGrid).SetCellStyle(pos, 1, cellStyle2);
    string str = robot.Controller.Name;
    if (!cellStyle2.ComboList.Contains(robot.Controller.Name))
      str = "default";
    ((C1FlexGridBase) this.m_controllersGrid).SetData(pos, 1, (object) str);
    if (str == "default")
    {
      ((C1FlexGridBase) this.m_controllersGrid).SetCellStyle(pos, 0, ((C1FlexGridBase) this.m_controllersGrid).Styles["ReadOnly"]);
      ((C1FlexGridBase) this.m_controllersGrid).SetCellStyle(pos, 3, ((C1FlexGridBase) this.m_controllersGrid).Styles["ReadOnly"]);
      ((C1FlexGridBase) this.m_controllersGrid).SetCellStyle(pos, 5, ((C1FlexGridBase) this.m_controllersGrid).Styles["ReadOnly"]);
      ((C1FlexGridBase) this.m_controllersGrid).SetCellStyle(pos, 6, ((C1FlexGridBase) this.m_controllersGrid).Styles["ReadOnly"]);
      ((C1FlexGridBase) this.m_controllersGrid).SetCellStyle(pos, 2, ((C1FlexGridBase) this.m_controllersGrid).Styles["ReadOnly"]);
      ((C1FlexGridBase) this.m_controllersGrid).SetCellStyle(pos, 4, ((C1FlexGridBase) this.m_controllersGrid).Styles["ReadOnly"]);
      ((C1FlexGridBase) this.m_controllersGrid).SetCellStyle(pos, 7, ((C1FlexGridBase) this.m_controllersGrid).Styles["ReadOnly"]);
      ((C1FlexGridBase) this.m_controllersGrid).SetData(pos, 4, (object) CUiRCSDecouplingDlg.MOP_STR);
      ((C1FlexGridBase) this.m_controllersGrid).SetData(pos, 7, (object) CUiRCSDecouplingDlg.VRC_NOT_SET_STATUS);
      this.DisableVRCColumns(pos);
    }
    else
      this.FillRobotControllerData(pos);
    CellStyle cellStyle3 = ((C1FlexGridBase) this.m_controllersGrid).GetCellStyle(pos, 5);
    if (cellStyle3 == null || !(cellStyle3.Name != "ReadOnly"))
      return;
    this.m_controllersGrid.SetCellImage(pos, 6, TxImageManager.GetImageByKey("FilterNoColor"), new Size());
  }

  private void DisableRRSColumns(int row)
  {
    ((C1FlexGridBase) this.m_controllersGrid).SetCellStyle(row, 5, ((C1FlexGridBase) this.m_controllersGrid).Styles["ReadOnly"]);
    ((C1FlexGridBase) this.m_controllersGrid).SetData(row, 5, (object) null);
    ((C1FlexGridBase) this.m_controllersGrid).SetCellStyle(row, 6, ((C1FlexGridBase) this.m_controllersGrid).Styles["ReadOnly"]);
    this.m_controllersGrid.SetCellImage(row, 6, (TxImage) null, new Size());
    ((C1FlexGridBase) this.m_controllersGrid).SetCellStyle(row, 7, ((C1FlexGridBase) this.m_controllersGrid).Styles["ReadOnly"]);
  }

  private void FillRobotControllerData(int row)
  {
    bool isRCSTerminated = false;
    TxOLPUtilities txOlpUtilities = new TxOLPUtilities();
    TxRobot robot = this.m_robots[row - 2] as TxRobot;
    ((C1FlexGridBase) this.m_controllersGrid).SetCellStyle(row, 0, ((C1FlexGridBase) this.m_controllersGrid).Styles["ReadOnly"]);
    this.UpdateRCSVersionCombo(row);
    this.UpdateManipulatorTypeCombo(row);
    this.UpdateControllerVersionCombo(row);
    this.UpdateMotionPlannerCombo(row);
    TxRcsDecouplingUtilities decouplingUtilities = new TxRcsDecouplingUtilities();
    CellStyle cellStyle = ((C1FlexGridBase) this.m_controllersGrid).GetCellStyle(row, 3);
    int num = 0;
    if (cellStyle != null && cellStyle.ComboList != null)
      num = cellStyle.ComboList.Length;
    if (robot.IsVRC)
    {
      if (this.m_VRCControlles.Contains((object) ((C1FlexGridBase) this.m_controllersGrid).GetData(row, 1).ToString()))
      {
        ((C1FlexGridBase) this.m_controllersGrid).SetData(row, 4, (object) CUiRCSDecouplingDlg.VRC_STR);
        TxRoboticStringParam instanceParameter1 = (TxRoboticStringParam) robot.GetInstanceParameter(this.VRC_HOST_PARAM);
        if (instanceParameter1 != null)
          ((C1FlexGridBase) this.m_controllersGrid).SetData(row, 8, (object) instanceParameter1.Value);
        else
          ((C1FlexGridBase) this.m_controllersGrid).SetData(row, 8, (object) this.DEFAULT_VRC_HOST);
        TxRoboticStringParam instanceParameter2 = (TxRoboticStringParam) robot.GetInstanceParameter(this.VRC_NAME_PARAM);
        if (instanceParameter2 != null)
          ((C1FlexGridBase) this.m_controllersGrid).SetData(row, 10, (object) instanceParameter2.Value);
        else
          ((C1FlexGridBase) this.m_controllersGrid).SetData(row, 10, (object) ((TxBaseGeometryCreationObject) robot).Name);
        TxRoboticIntParam instanceParameter3 = (TxRoboticIntParam) robot.GetInstanceParameter(this.VRC_PORT_PARAM);
        if (instanceParameter3 != null)
          ((C1FlexGridBase) this.m_controllersGrid).SetData(row, 9, (object) instanceParameter3.Value);
        else
          ((C1FlexGridBase) this.m_controllersGrid).SetData(row, 9, (object) this.DEFAULT_VRC_PORT);
        ((C1FlexGridBase) this.m_controllersGrid).SetCellStyle(row, 8, "");
        ((C1FlexGridBase) this.m_controllersGrid).SetCellStyle(row, 9, "");
        ((C1FlexGridBase) this.m_controllersGrid).SetCellStyle(row, 10, "");
        ((C1FlexGridBase) this.m_controllersGrid).SetCellStyle(row, 11, ((C1FlexGridBase) this.m_controllersGrid).Styles["ReadOnly"]);
        this.UpdateVRCProgramPointerColumn(row);
      }
      else
      {
        ((C1FlexGridBase) this.m_controllersGrid).SetData(row, 4, (object) CUiRCSDecouplingDlg.MOP_STR);
        this.DisableVRCColumns(row);
      }
      this.DisableRRSColumns(row);
    }
    else if (decouplingUtilities.IsRCSTurnedOffForNonSimulationActionsSupported(((C1FlexGridBase) this.m_controllersGrid).GetData(row, 1).ToString()) && decouplingUtilities.IsRCSTurnedOffForSimulationActionsSupported(((C1FlexGridBase) this.m_controllersGrid).GetData(row, 1).ToString()) && num > 0)
    {
      this.DisableVRCColumns(row);
      if (!robot.IsRCSTurnedOffForSimulationActions)
      {
        ((C1FlexGridBase) this.m_controllersGrid).SetData(row, 4, (object) CUiRCSDecouplingDlg.RCS_STR);
        if (this.m_nonSimDisabledIndexes.Contains((object) row))
          this.m_nonSimDisabledIndexes.Remove((object) row);
        if (this.m_simDisabledIndexes.Contains((object) row))
          this.m_simDisabledIndexes.Remove((object) row);
      }
      else if (!robot.IsRCSTurnedOffForNonSimulationActions)
      {
        ((C1FlexGridBase) this.m_controllersGrid).SetData(row, 4, (object) CUiRCSDecouplingDlg.RCS_NON_SIMULATION_STR);
        if (this.m_nonSimDisabledIndexes.Contains((object) row))
          this.m_nonSimDisabledIndexes.Remove((object) row);
        if (this.m_simDisabledIndexes.Contains((object) row))
          this.m_simDisabledIndexes.Remove((object) row);
      }
      else
      {
        ((C1FlexGridBase) this.m_controllersGrid).SetData(row, 4, (object) CUiRCSDecouplingDlg.MOP_STR);
        if (this.m_nonSimDisabledIndexes.Contains((object) row))
          this.m_nonSimDisabledIndexes.Remove((object) row);
        if (this.m_simDisabledIndexes.Contains((object) row))
          this.m_simDisabledIndexes.Remove((object) row);
        this.DisableRRSColumns(row);
      }
    }
    else
    {
      robot.IsRCSTurnedOffForNonSimulationActions = true;
      robot.IsRCSTurnedOffForSimulationActions = true;
      ((C1FlexGridBase) this.m_controllersGrid).SetData(row, 4, (object) CUiRCSDecouplingDlg.MOP_STR);
      if (!this.m_nonSimDisabledIndexes.Contains((object) row))
        this.m_nonSimDisabledIndexes.Add((object) row);
      if (!this.m_simDisabledIndexes.Contains((object) row))
        this.m_simDisabledIndexes.Add((object) row);
      this.DisableRRSColumns(row);
      this.DisableVRCColumns(row);
    }
    if (this.DoesRCSExistAndValid(robot, ref isRCSTerminated))
      ((C1FlexGridBase) this.m_controllersGrid).SetData(row, 7, (object) CUiRCSDStringTable.RCS_STATUS_LOADED);
    else
      ((C1FlexGridBase) this.m_controllersGrid).SetData(row, 7, (object) CUiRCSDecouplingDlg.VRC_NOT_SET_STATUS);
  }

  private void FindVRCControllers()
  {
    string installationDirectory = new TxOLPUtilities().GetOLPInstallationDirectory();
    if (!Directory.Exists(installationDirectory))
      return;
    foreach (string subDirectory in this.GetSubDirectories(installationDirectory))
    {
      foreach (string file in Directory.GetFiles(subDirectory, "*.dll"))
      {
        Assembly assembly = (Assembly) null;
        try
        {
          assembly = Assembly.LoadFrom(file);
        }
        catch
        {
        }
        if (assembly != (Assembly) null)
        {
          Type[] typeArray;
          try
          {
            typeArray = assembly.GetExportedTypes();
          }
          catch
          {
            typeArray = (Type[]) null;
          }
          string empty = string.Empty;
          if (typeArray != null)
          {
            foreach (Type type in typeArray)
            {
              if (type.GetInterface("ITxVRCController") != (Type) null)
              {
                TxRobotSimulationControllerAttribute customAttribute = (TxRobotSimulationControllerAttribute) Attribute.GetCustomAttribute((MemberInfo) type, typeof (TxRobotSimulationControllerAttribute));
                if (customAttribute != null && (ITxVRCController) Activator.CreateInstance(type) != null)
                  this.m_VRCControlles.Add((object) customAttribute.ControllerName);
              }
            }
          }
        }
      }
    }
  }

  private void FillControllers()
  {
    string installationDirectory = new TxOLPUtilities().GetOLPInstallationDirectory();
    if (!Directory.Exists(installationDirectory))
      return;
    ArrayList subDirectories = this.GetSubDirectories(installationDirectory);
    int num1 = 1;
    foreach (string path in subDirectories)
    {
      foreach (string file in Directory.GetFiles(path, "*.dll"))
      {
        Assembly assembly = Assembly.LoadFrom(file);
        if (assembly != (Assembly) null)
        {
          Type[] exportedTypes = assembly.GetExportedTypes();
          int num2 = 0;
          string controllerName = string.Empty;
          bool flag1 = false;
          bool flag2 = false;
          foreach (Type type in exportedTypes)
          {
            if (type.GetInterface("ITxRobotSimulationController") != (Type) null)
            {
              TxRobotSimulationControllerAttribute customAttribute = (TxRobotSimulationControllerAttribute) Attribute.GetCustomAttribute((MemberInfo) type, typeof (TxRobotSimulationControllerAttribute));
              if (customAttribute != null && (ITxRobotSimulationController) Activator.CreateInstance(type) != null)
              {
                if (num2 < 1)
                  controllerName = customAttribute.ControllerName;
                ++num2;
              }
            }
            if (type.GetInterface("ITxRRSController") != (Type) null && (TxRobotSimulationControllerAttribute) Attribute.GetCustomAttribute((MemberInfo) type, typeof (TxRobotSimulationControllerAttribute)) != null)
            {
              ITxRRSController instance = (ITxRRSController) Activator.CreateInstance(type);
              if (instance != null)
              {
                flag2 = true;
                flag1 = instance.IsRCSTurnedOffForNonSimulationActionsSupported();
              }
            }
          }
          if (flag2)
          {
            RowCollection rows = ((C1FlexGridBase) this.m_controllersGrid).Rows;
            ((RowColCollection) rows).Count = ((RowColCollection) rows).Count + 1;
            if (num2 < 2)
              this.AddReadOnlyCell(num1, 2);
            if (!flag1)
              this.AddReadOnlyCell(num1, 1);
            this.AddControllerToGrid(num1, controllerName);
            ++num1;
          }
        }
      }
    }
  }

  private void AddReadOnlyCell(int row, int col)
  {
    this.m_readOnlyCells.Add(new CUiRCSDecoupleReadOnlyCell(row, col));
    ((C1FlexGridBase) this.m_controllersGrid).SetCellStyle(row, col, ((C1FlexGridBase) this.m_controllersGrid).Styles["ReadOnly"]);
  }

  private void AddControllerToGrid(int pos, string controllerName)
  {
    TxRCSDecouple txRcsDecouple = new TxRCSDecouple();
    ((C1FlexGridBase) this.m_controllersGrid).SetData(pos, 0, (object) controllerName);
    ((C1FlexGridBase) this.m_controllersGrid).SetData(pos, 1, (object) txRcsDecouple.IsRCSTurnedOffForNonSimulationActions(controllerName));
    ((C1FlexGridBase) this.m_controllersGrid).SetData(pos, 2, (object) txRcsDecouple.IsRCSTurnedOffForSimulationActions(controllerName));
  }

  private void UpdateMotionPlannerCombo(int row)
  {
    ((C1FlexGridBase) this.m_controllersGrid).GetData(row, 4);
    string str = ((C1FlexGridBase) this.m_controllersGrid).GetData(row, 1).ToString();
    bool flag = true;
    ArrayList installedVersions = new TxOLPUtilities().GetControllerInstalledVersions(str);
    if (installedVersions != null && installedVersions.Count > 0)
      flag = false;
    CellStyle cellStyle = ((C1FlexGridBase) this.m_controllersGrid).Styles.Add("MotionPlannerCombo" + ((TxBaseGeometryCreationObject) (this.m_robots[row - 2] as TxRobot)).Id);
    cellStyle.ComboList = "";
    cellStyle.ComboList += CUiRCSDecouplingDlg.MOP_STR;
    if (!flag)
    {
      cellStyle.ComboList += "|";
      cellStyle.ComboList += CUiRCSDecouplingDlg.RCS_STR;
      cellStyle.ComboList += "|";
      cellStyle.ComboList += CUiRCSDecouplingDlg.RCS_NON_SIMULATION_STR;
    }
    if (this.m_VRCControlles.Contains((object) str))
    {
      cellStyle.ComboList += "|";
      cellStyle.ComboList += CUiRCSDecouplingDlg.VRC_STR;
    }
    if (cellStyle.ComboList.Equals(CUiRCSDecouplingDlg.MOP_STR))
    {
      ((C1FlexGridBase) this.m_controllersGrid).SetCellStyle(row, 4, ((C1FlexGridBase) this.m_controllersGrid).Styles["ReadOnly"]);
      ((C1FlexGridBase) this.m_controllersGrid).SetData(row, 4, (object) CUiRCSDecouplingDlg.MOP_STR);
    }
    else
      ((C1FlexGridBase) this.m_controllersGrid).SetCellStyle(row, 4, cellStyle);
  }

  private void UpdateControllerVersionCombo(int row)
  {
    TxRobot robot = this.m_robots[row - 2] as TxRobot;
    ITxRoboticControllerServices implementationFromController = (ITxRoboticControllerServices) new TxOlpControllerUtilities().GetInterfaceImplementationFromController(((C1FlexGridBase) this.m_controllersGrid).GetData(row, 1).ToString(), typeof (ITxRoboticControllerServices), typeof (TxControllerAttribute), "ControllerName");
    bool flag = false;
    string str1 = "";
    if (robot.GetInstanceParameter(this.CONTROLLER_VERSION_PARAM) is TxRoboticStringParam instanceParameter)
      str1 = instanceParameter.Value;
    CellStyle cellStyle = ((C1FlexGridBase) this.m_controllersGrid).Styles.Add("ControllerVersionCombo" + ((TxBaseGeometryCreationObject) robot).Id);
    cellStyle.ComboList = "";
    if (implementationFromController != null)
    {
      string[] controllerVersions = implementationFromController.GetAvailableControllerVersions(robot);
      if (controllerVersions == null || controllerVersions.Length == 0)
      {
        ((C1FlexGridBase) this.m_controllersGrid).SetCellStyle(row, 2, ((C1FlexGridBase) this.m_controllersGrid).Styles["ReadOnly"]);
        ((C1FlexGridBase) this.m_controllersGrid).SetData(row, 2, (object) null);
      }
      else
      {
        foreach (string str2 in controllerVersions)
        {
          if (str2 == str1)
            flag = true;
          cellStyle.ComboList += str2;
          cellStyle.ComboList += "|";
        }
        ((C1FlexGridBase) this.m_controllersGrid).SetCellStyle(row, 2, cellStyle);
      }
    }
    if (instanceParameter != null & flag)
      ((C1FlexGridBase) this.m_controllersGrid).SetData(row, 2, (object) str1);
    else
      ((C1FlexGridBase) this.m_controllersGrid).SetData(row, 2, (object) "");
  }

  private void UpdateManipulatorTypeCombo(int row)
  {
    string str1 = "";
    if (((C1FlexGridBase) this.m_controllersGrid).GetUserData(row, 6) != null && ((C1FlexGridBase) this.m_controllersGrid).GetCellImage(row, 6) != null)
      str1 = ((C1FlexGridBase) this.m_controllersGrid).GetUserData(row, 6).ToString();
    TxRobot robot = this.m_robots[row - 2] as TxRobot;
    ITxRoboticControllerServices implementationFromController = (ITxRoboticControllerServices) new TxOlpControllerUtilities().GetInterfaceImplementationFromController(((C1FlexGridBase) this.m_controllersGrid).GetData(row, 1).ToString(), typeof (ITxRoboticControllerServices), typeof (TxControllerAttribute), "ControllerName");
    CellStyle cellStyle = ((C1FlexGridBase) this.m_controllersGrid).Styles.Add("ManipulatorTypeCombo" + ((TxBaseGeometryCreationObject) robot).Id);
    cellStyle.ComboList = "|";
    if (implementationFromController == null)
      return;
    string[] manipulatorTypes = implementationFromController.GetAvailableManipulatorTypes(robot);
    if (manipulatorTypes != null)
    {
      ArrayList arrayList = new ArrayList();
      foreach (string str2 in manipulatorTypes)
      {
        if (str2.IndexOf(str1, StringComparison.OrdinalIgnoreCase) >= 0)
          arrayList.Add((object) str2);
      }
      arrayList.Sort();
      foreach (string str3 in arrayList)
      {
        cellStyle.ComboList += str3;
        cellStyle.ComboList += "|";
      }
      ((C1FlexGridBase) this.m_controllersGrid).SetCellStyle(row, 5, cellStyle);
      ((C1FlexGridBase) this.m_controllersGrid).Invalidate();
      if (!(robot.Controller is TxRobotRRSController controller))
        return;
      ((C1FlexGridBase) this.m_controllersGrid).SetData(row, 5, (object) controller.ManipulatorType);
      if (((C1FlexGridBase) this.m_controllersGrid).GetCellImage(row, 6) != null)
        return;
      this.m_controllersGrid.SetCellImage(row, 6, TxImageManager.GetImageByKey("FilterNoColor"), new Size());
    }
    else
    {
      ((C1FlexGridBase) this.m_controllersGrid).SetCellStyle(row, 5, ((C1FlexGridBase) this.m_controllersGrid).Styles["ReadOnly"]);
      ((C1FlexGridBase) this.m_controllersGrid).SetCellStyle(row, 6, ((C1FlexGridBase) this.m_controllersGrid).Styles["ReadOnly"]);
      this.m_controllersGrid.SetCellImage(row, 6, (TxImage) null, new Size());
      this.UpdateControllerVersionCombo(row);
    }
  }

  private void UpdateRCSVersionCombo(int row)
  {
    TxOLPUtilities txOlpUtilities = new TxOLPUtilities();
    TxRobot robot = this.m_robots[row - 2] as TxRobot;
    TxRobotRRSController controller = robot.Controller as TxRobotRRSController;
    string str1 = ((C1FlexGridBase) this.m_controllersGrid).GetData(row, 1).ToString();
    ArrayList installedVersions = txOlpUtilities.GetControllerInstalledVersions(str1);
    if (installedVersions != null && installedVersions.Count > 0)
    {
      CellStyle cellStyle = ((C1FlexGridBase) this.m_controllersGrid).Styles.Add("RcsVersionCombo" + ((TxBaseGeometryCreationObject) robot).Id);
      cellStyle.ComboList = "";
      foreach (string str2 in installedVersions)
      {
        cellStyle.ComboList += str2;
        cellStyle.ComboList += "|";
      }
      ((C1FlexGridBase) this.m_controllersGrid).SetCellStyle(row, 3, cellStyle);
      if (controller != null && installedVersions.Contains((object) controller.Version))
        ((C1FlexGridBase) this.m_controllersGrid).SetData(row, 3, (object) controller.Version);
      else if (controller != null && controller.Version != "")
      {
        string str3 = $"{CUiRCSDStringTable.INVALID_STR} {controller.Version}";
        string str4 = $"{str3}|{cellStyle.ComboList}";
        cellStyle.ComboList = str4;
        ((C1FlexGridBase) this.m_controllersGrid).SetData(row, 3, (object) str3);
      }
      else
        ((C1FlexGridBase) this.m_controllersGrid).SetData(row, 3, (object) "");
    }
    else
    {
      ((C1FlexGridBase) this.m_controllersGrid).SetData(row, 3, (object) null);
      ((C1FlexGridBase) this.m_controllersGrid).SetCellStyle(row, 3, ((C1FlexGridBase) this.m_controllersGrid).Styles["ReadOnly"]);
      if (controller.Version != "")
      {
        string str5 = $"{CUiRCSDStringTable.INVALID_STR} {controller.Version}";
        ((C1FlexGridBase) this.m_controllersGrid).SetData(row, 3, (object) str5);
      }
      else
        ((C1FlexGridBase) this.m_controllersGrid).SetData(row, 3, (object) "");
      robot.IsRCSTurnedOffForSimulationActions = true;
      if (!this.m_simDisabledIndexes.Contains((object) row))
        this.m_simDisabledIndexes.Add((object) row);
      ((C1FlexGridBase) this.m_controllersGrid).SetCellStyle(row, 4, ((C1FlexGridBase) this.m_controllersGrid).Styles["ReadOnly"]);
      ((C1FlexGridBase) this.m_controllersGrid).SetData(row, 4, (object) CUiRCSDecouplingDlg.MOP_STR);
      robot.IsRCSTurnedOffForNonSimulationActions = true;
      if (this.m_nonSimDisabledIndexes.Contains((object) row))
        return;
      this.m_nonSimDisabledIndexes.Add((object) row);
    }
  }

  private HashSet<string> GetAllColumnPossibleValues(int col)
  {
    HashSet<string> columnPossibleValues = new HashSet<string>();
    for (int index = 2; index < ((RowColCollection) ((C1FlexGridBase) this.m_controllersGrid).Rows).Count; ++index)
    {
      object data = ((C1FlexGridBase) this.m_controllersGrid).GetData(index, col);
      CellStyle cellStyle = ((C1FlexGridBase) this.m_controllersGrid).GetCellStyle(index, col);
      if (cellStyle == null || cellStyle.ComboList == string.Empty)
      {
        if (data != null)
          columnPossibleValues.Add(data.ToString());
      }
      else
      {
        string[] strArray = ((C1FlexGridBase) this.m_controllersGrid).GetCellStyle(index, col).ComboList.Split('|');
        HashSet<string> stringSet = new HashSet<string>();
        foreach (string str in strArray)
          stringSet.Add(str);
        if (columnPossibleValues.Count > 0)
          columnPossibleValues.IntersectWith((IEnumerable<string>) stringSet);
        else
          columnPossibleValues = new HashSet<string>((IEnumerable<string>) stringSet);
      }
    }
    return columnPossibleValues;
  }

  private HashSet<string> GetColumnValues(int col)
  {
    HashSet<string> columnValues = new HashSet<string>();
    for (int index = 2; index < ((RowColCollection) ((C1FlexGridBase) this.m_controllersGrid).Rows).Count; ++index)
    {
      object data = ((C1FlexGridBase) this.m_controllersGrid).GetData(index, col);
      if (data != null)
        columnValues.Add(data.ToString());
    }
    return columnValues;
  }

  private bool ShouldShowSetAllContextMenu(
    HitTestInfo hitTestInfo,
    HashSet<string> ControllerValues)
  {
    HashSet<string> stringSet = this.isVRCColumn(hitTestInfo) ? this.ReduceDifferentControllerFlavorsToOne(ControllerValues) : ControllerValues;
    if (((HitTestInfo) ref hitTestInfo).Column <= -1 || ((HitTestInfo) ref hitTestInfo).Column == 0 || ((HitTestInfo) ref hitTestInfo).Column == 7 || ((HitTestInfo) ref hitTestInfo).Row != 1)
      return false;
    return stringSet.Count == 1 || stringSet.Count == 2 && stringSet.Contains("default") || ((HitTestInfo) ref hitTestInfo).Column == 1;
  }

  private bool isVRCColumn(HitTestInfo hitTestInfo)
  {
    int column = ((HitTestInfo) ref hitTestInfo).Column;
    switch (column)
    {
      case 8:
      case 9:
      case 11:
        return true;
      default:
        return column == 10;
    }
  }

  private HashSet<string> ReduceDifferentControllerFlavorsToOne(HashSet<string> controllerValues)
  {
    HashSet<string> one = new HashSet<string>();
    foreach (string controllerValue in controllerValues)
    {
      if (controllerValue.ToLower().StartsWith("fanuc"))
        one.Add("Fanuc");
      else if (controllerValue.ToLower().StartsWith("kuka"))
        one.Add("Kuka");
      else
        one.Add(controllerValue);
    }
    return one;
  }

  private void m_controllersGrid_MouseMove(object sender, MouseEventArgs e)
  {
    int mouseRow = ((C1FlexGridBase) this.m_controllersGrid).MouseRow;
    int mouseCol = ((C1FlexGridBase) this.m_controllersGrid).MouseCol;
    if (mouseCol == 6 && ((C1FlexGridBase) this.m_controllersGrid).GetUserData(mouseRow, mouseCol) != null)
      this.m_tooltip.SetToolTip((Control) this.m_controllersGrid, ((C1FlexGridBase) this.m_controllersGrid).GetUserData(mouseRow, mouseCol).ToString());
    else
      this.m_tooltip.RemoveAll();
  }

  private void m_controllersGrid_MouseClick(object sender, MouseEventArgs e)
  {
    HitTestInfo hitTestInfo = ((C1FlexGridBase) this.m_controllersGrid).HitTest();
    if (((HitTestInfo) ref hitTestInfo).Row <= 1 || ((HitTestInfo) ref hitTestInfo).Column != 6)
      return;
    CellStyle cellStyle = ((C1FlexGridBase) this.m_controllersGrid).GetCellStyle(((HitTestInfo) ref hitTestInfo).Row, 5);
    if (cellStyle != null && cellStyle.Name == "ReadOnly")
      return;
    object userData = ((C1FlexGridBase) this.m_controllersGrid).GetUserData(((HitTestInfo) ref hitTestInfo).Row, 6);
    int row = ((HitTestInfo) ref hitTestInfo).Row;
    Point screen = ((Control) this).PointToScreen(new Point(e.X, e.Y));
    this.m_filterDlg = userData == null ? new CUiRCSDecouplingManipulatorFilterDlg(screen.X, screen.Y + 40) : new CUiRCSDecouplingManipulatorFilterDlg(screen.X, screen.Y + 40, userData.ToString());
    this.m_filterDlg.DialogClosed += new EventHandler(this.filterDlg_DialogClosed);
    ((Form) this.m_filterDlg).TopMost = false;
    int num = (int) ((Form) this.m_filterDlg).ShowDialog((IWin32Window) this);
  }

  private void filterDlg_DialogClosed(object sender, EventArgs e)
  {
    CUiRCSDecouplingManipulatorFilterDlg manipulatorFilterDlg = sender as CUiRCSDecouplingManipulatorFilterDlg;
    if (manipulatorFilterDlg.FilterString == "")
      ((C1FlexGridBase) this.m_controllersGrid).SetUserData(((C1FlexGridBase) this.m_controllersGrid).RowSel, 6, (object) null);
    else
      ((C1FlexGridBase) this.m_controllersGrid).SetUserData(((C1FlexGridBase) this.m_controllersGrid).RowSel, 6, (object) manipulatorFilterDlg.FilterString);
    ((C1FlexGridBase) this.m_controllersGrid).GetCellStyle(((C1FlexGridBase) this.m_controllersGrid).RowSel, 5);
    CellStyle cellStyle = ((C1FlexGridBase) this.m_controllersGrid).GetCellStyle(((C1FlexGridBase) this.m_controllersGrid).RowSel, 5);
    if (((C1FlexGridBase) this.m_controllersGrid).ColSel == 6 && cellStyle != null && cellStyle.Name != "ReadOnly")
    {
      if (((C1FlexGridBase) this.m_controllersGrid).GetUserData(((C1FlexGridBase) this.m_controllersGrid).RowSel, 6) != null)
        this.m_controllersGrid.SetCellImage(((C1FlexGridBase) this.m_controllersGrid).RowSel, 6, TxImageManager.GetImageByKey("FilterFilled"), new Size());
      else
        this.m_controllersGrid.SetCellImage(((C1FlexGridBase) this.m_controllersGrid).RowSel, 6, TxImageManager.GetImageByKey("FilterNoColor"), new Size());
    }
    this.UpdateManipulatorTypeCombo(((C1FlexGridBase) this.m_controllersGrid).RowSel);
    this.m_filterDlg.DialogClosed -= new EventHandler(this.filterDlg_DialogClosed);
    this.m_filterDlg = (CUiRCSDecouplingManipulatorFilterDlg) null;
  }

  private void CUiRCSDecouplingDlg_FormClosing(object sender, FormClosingEventArgs e)
  {
    if (this.m_iftArResult == null || this.m_iftArResult.IsCompleted)
      return;
    e.Cancel = true;
  }

  private void setAllWithVRCToolStripMenuItem_Click(object sender, EventArgs e)
  {
    this.ApplyToolStripMenuItemValue(CUiRCSDecouplingDlg.VRC_STR);
  }

  private void setAllWithMOPToolStripMenuItem_Click(object sender, EventArgs e)
  {
    this.ApplyToolStripMenuItemValue(CUiRCSDecouplingDlg.MOP_STR);
  }

  private void setAllWithRRSStaticToolStripMenuItem_Click(object sender, EventArgs e)
  {
    this.ApplyToolStripMenuItemValue(CUiRCSDecouplingDlg.RCS_NON_SIMULATION_STR);
  }

  private void setAllWithRRSToolStripMenuItem_Click(object sender, EventArgs e)
  {
    this.ApplyToolStripMenuItemValue(CUiRCSDecouplingDlg.RCS_STR);
  }

  private void ApplyToolStripMenuItemValue(string val)
  {
    ((C1FlexGridBase) this.m_controllersGrid).Select(0, 0);
    for (int rawIndex = 0; rawIndex < ((RowColCollection) ((C1FlexGridBase) this.m_controllersGrid).Rows).Count; ++rawIndex)
    {
      CellStyle cellStyle = ((C1FlexGridBase) this.m_controllersGrid).GetCellStyle(rawIndex, 4);
      if (cellStyle != null && cellStyle.ComboList.Contains(val))
      {
        ((C1FlexGridBase) this.m_controllersGrid).SetData(rawIndex, 4, (object) val);
        this.ApplyMotionPlannerValue(rawIndex);
      }
    }
  }

  protected virtual void Dispose(bool disposing)
  {
    if (disposing && this.components != null)
      this.components.Dispose();
    base.Dispose(disposing);
  }

  private void InitializeComponent()
  {
    this.components = (IContainer) new Container();
    ComponentResourceManager componentResourceManager = new ComponentResourceManager(typeof (CUiRCSDecouplingDlg));
    this.m_controllersGrid = new TxFlexGrid();
    this.contextMenuStrip1 = new ContextMenuStrip(this.components);
    this.setAllWithMOPToolStripMenuItem = new ToolStripMenuItem();
    this.RRSToolStripMenuItem = new ToolStripMenuItem();
    this.setAllWithRRSStaticToolStripMenuItem = new ToolStripMenuItem();
    this.setAllWithVRCToolStripMenuItem = new ToolStripMenuItem();
    this.m_toolbar = new TxToolBar();
    this.m_validateButton = new TxToolBarButton();
    this.m_validateAllButton = new TxToolBarButton();
    this.m_terminateRCSButton = new TxToolBarButton();
    this.m_terminateAllRCSButton = new TxToolBarButton();
    this.m_robotSetupButton = new TxToolBarButton();
    this.m_imageList = new ImageList(this.components);
    this.m_btnClose = new Button();
    this.m_validateProgressBar = new TxProgressBar();
    this.m_InfoToolTip = new ToolTip(this.components);
    this.m_InfoIcon = new TxInfoButton();
    ((ISupportInitialize) this.m_controllersGrid).BeginInit();
    this.contextMenuStrip1.SuspendLayout();
    ((Control) this).SuspendLayout();
    ((C1FlexGridBase) this.m_controllersGrid).AllowDragging = (AllowDraggingEnum) 0;
    ((C1.Win.C1FlexGrid.C1FlexGrid) this.m_controllersGrid).AllowMerging = (AllowMergingEnum) 5;
    componentResourceManager.ApplyResources((object) this.m_controllersGrid, "m_controllersGrid");
    ((C1FlexGridBase) this.m_controllersGrid).EditOptions = (EditFlags) 29;
    ((C1FlexGridBase) this.m_controllersGrid).ExtendLastCol = true;
    ((Control) this.m_controllersGrid).Name = "m_controllersGrid";
    ((RowColCollection) ((C1FlexGridBase) this.m_controllersGrid).Rows).Count = 15;
    ((RowColCollection) ((C1FlexGridBase) this.m_controllersGrid).Rows).DefaultSize = 19;
    ((RowColCollection) ((C1FlexGridBase) this.m_controllersGrid).Rows).Fixed = 2;
    ((C1FlexGridBase) this.m_controllersGrid).SelectionMode = (SelectionModeEnum) 1;
    ((C1FlexGridBase) this.m_controllersGrid).ShowButtons = (ShowButtonsEnum) 2;
    ((C1FlexGridBase) this.m_controllersGrid).StyleInfo = componentResourceManager.GetString("m_controllersGrid.StyleInfo");
    ((C1FlexGridBase) this.m_controllersGrid).SelChange += new EventHandler(this.m_controllersGrid_SelChange);
    ((C1FlexGridBase) this.m_controllersGrid).BeforeEdit += new RowColEventHandler(this.m_controllersGrid_BeforeEdit);
    ((C1FlexGridBase) this.m_controllersGrid).AfterEdit += new RowColEventHandler(this.m_controllersGrid_AfterEdit);
    ((Control) this.m_controllersGrid).MouseClick += new MouseEventHandler(this.m_controllersGrid_MouseClick);
    ((Control) this.m_controllersGrid).MouseDown += new MouseEventHandler(this.m_controllersGrid_MouseDown);
    ((Control) this.m_controllersGrid).MouseMove += new MouseEventHandler(this.m_controllersGrid_MouseMove);
    this.contextMenuStrip1.ImageScalingSize = new Size(20, 20);
    this.contextMenuStrip1.Items.AddRange(new ToolStripItem[4]
    {
      (ToolStripItem) this.setAllWithMOPToolStripMenuItem,
      (ToolStripItem) this.RRSToolStripMenuItem,
      (ToolStripItem) this.setAllWithRRSStaticToolStripMenuItem,
      (ToolStripItem) this.setAllWithVRCToolStripMenuItem
    });
    this.contextMenuStrip1.Name = "contextMenuStrip1";
    componentResourceManager.ApplyResources((object) this.contextMenuStrip1, "contextMenuStrip1");
    this.setAllWithMOPToolStripMenuItem.Name = "setAllWithMOPToolStripMenuItem";
    componentResourceManager.ApplyResources((object) this.setAllWithMOPToolStripMenuItem, "setAllWithMOPToolStripMenuItem");
    this.setAllWithMOPToolStripMenuItem.Click += new EventHandler(this.setAllWithMOPToolStripMenuItem_Click);
    this.RRSToolStripMenuItem.Name = "RRSToolStripMenuItem";
    componentResourceManager.ApplyResources((object) this.RRSToolStripMenuItem, "RRSToolStripMenuItem");
    this.RRSToolStripMenuItem.Click += new EventHandler(this.setAllWithRRSToolStripMenuItem_Click);
    this.setAllWithRRSStaticToolStripMenuItem.Name = "setAllWithRRSStaticToolStripMenuItem";
    componentResourceManager.ApplyResources((object) this.setAllWithRRSStaticToolStripMenuItem, "setAllWithRRSStaticToolStripMenuItem");
    this.setAllWithRRSStaticToolStripMenuItem.Click += new EventHandler(this.setAllWithRRSStaticToolStripMenuItem_Click);
    this.setAllWithVRCToolStripMenuItem.Name = "setAllWithVRCToolStripMenuItem";
    componentResourceManager.ApplyResources((object) this.setAllWithVRCToolStripMenuItem, "setAllWithVRCToolStripMenuItem");
    this.setAllWithVRCToolStripMenuItem.Click += new EventHandler(this.setAllWithVRCToolStripMenuItem_Click);
    componentResourceManager.ApplyResources((object) this.m_toolbar, "m_toolbar");
    ((ToolBar) this.m_toolbar).Buttons.AddRange(new ToolBarButton[5]
    {
      (ToolBarButton) this.m_validateButton,
      (ToolBarButton) this.m_validateAllButton,
      (ToolBarButton) this.m_terminateRCSButton,
      (ToolBarButton) this.m_terminateAllRCSButton,
      (ToolBarButton) this.m_robotSetupButton
    });
    ((ToolBar) this.m_toolbar).Divider = false;
    ((ToolBar) this.m_toolbar).ImageList = this.m_imageList;
    ((Control) this.m_toolbar).Name = "m_toolbar";
    ((ToolBar) this.m_toolbar).ButtonClick += new ToolBarButtonClickEventHandler(this.m_toolbar_ButtonClick);
    componentResourceManager.ApplyResources((object) this.m_validateButton, "m_validateButton");
    ((ToolBarButton) this.m_validateButton).Name = "m_validateButton";
    componentResourceManager.ApplyResources((object) this.m_validateAllButton, "m_validateAllButton");
    ((ToolBarButton) this.m_validateAllButton).Name = "m_validateAllButton";
    componentResourceManager.ApplyResources((object) this.m_terminateRCSButton, "m_terminateRCSButton");
    ((ToolBarButton) this.m_terminateRCSButton).Name = "m_terminateRCSButton";
    componentResourceManager.ApplyResources((object) this.m_terminateAllRCSButton, "m_terminateAllRCSButton");
    ((ToolBarButton) this.m_terminateAllRCSButton).Name = "m_terminateAllRCSButton";
    componentResourceManager.ApplyResources((object) this.m_robotSetupButton, "m_robotSetupButton");
    ((ToolBarButton) this.m_robotSetupButton).Name = "m_robotSetupButton";
    this.m_imageList.ImageStream = (ImageListStreamer) componentResourceManager.GetObject("m_imageList.ImageStream");
    this.m_imageList.TransparentColor = Color.Transparent;
    this.m_imageList.Images.SetKeyName(0, "RobotSetup.ico");
    this.m_imageList.Images.SetKeyName(1, "validate_robot.ico");
    this.m_imageList.Images.SetKeyName(2, "validate_all_robots.ico");
    this.m_imageList.Images.SetKeyName(3, "TerminateRCS.ico");
    this.m_imageList.Images.SetKeyName(4, "terminate_all_rcs.ico");
    componentResourceManager.ApplyResources((object) this.m_btnClose, "m_btnClose");
    this.m_btnClose.DialogResult = DialogResult.OK;
    this.m_btnClose.Name = "m_btnClose";
    this.m_btnClose.Click += new EventHandler(this.m_btnClose_Click);
    componentResourceManager.ApplyResources((object) this.m_validateProgressBar, "m_validateProgressBar");
    ((Control) this.m_validateProgressBar).Name = "m_validateProgressBar";
    componentResourceManager.ApplyResources((object) this.m_InfoIcon, "m_InfoIcon");
    ((Control) this.m_InfoIcon).Name = "m_InfoIcon";
    this.m_InfoIcon.TabStop = true;
    this.m_InfoIcon.TooltipDuration = 5000;
    this.m_InfoIcon.TooltipText = (string) null;
    this.m_InfoIcon.TooltipTitle = "";
    this.m_InfoIcon.Type = (TxInfoButton.InfoType) 0;
    componentResourceManager.ApplyResources((object) this, "$this");
    ((ContainerControl) this).AutoScaleMode = AutoScaleMode.Font;
    ((Control) this).Controls.Add((Control) this.m_InfoIcon);
    ((Control) this).Controls.Add((Control) this.m_validateProgressBar);
    ((Control) this).Controls.Add((Control) this.m_btnClose);
    ((Control) this).Controls.Add((Control) this.m_controllersGrid);
    ((Control) this).Controls.Add((Control) this.m_toolbar);
    ((Control) this).Name = nameof (CUiRCSDecouplingDlg);
    ((Form) this).FormClosing += new FormClosingEventHandler(this.CUiRCSDecouplingDlg_FormClosing);
    ((Form) this).FormClosed += new FormClosedEventHandler(this.CUiRCSDecouplingDlg_FormClosed);
    ((Form) this).Load += new EventHandler(this.CUiRCSDecouplingDlg_Load);
    ((ISupportInitialize) this.m_controllersGrid).EndInit();
    this.contextMenuStrip1.ResumeLayout(false);
    ((Control) this).ResumeLayout(false);
  }

  private enum EGridToolbarBtns
  {
    ValidateSelected,
    ValidateAll,
    TerminateRCS,
    TerminateAllRCS,
    RobotSetup,
  }

  private enum RCSModuleStatus
  {
    RCSUnvalidParams,
    RCSValidAndInitialized,
    RCSValid,
    RCSCommunicationFailed,
  }
}
